January 16, 2024
bash
or zsh
powerlevel10k
or starship
firefox
or chrome
vim
or emacs
… How do we characterize the execution environment of these programs? … How do we compare their performance in different configurations? … How do we improve their performance? …
ds2
package in donsheehy/datastructures book and package code
systemsense
toolCommands
benchmarkinfo: Benchmark the system used for experiments.
completeinfo: Detect information about and then benchmark the system used for experiments.
systeminfo: Detect all relevant information about the system used for experiments.
systeminfo
: use packages like psutil
to collect relevant information about the execution environment, suitable for characterizing and comparing local and cloud-based systemsbenchmarkinfo
: use packages like timeit
to run simple micro-benchmarks involving basic operations so as to characterize baseline system performancedef get_cpu() -> Dict[str, str]:
"""Return information about the current CPU in the system."""
# detect the name of the function in
# which this source code exists
function_name = inspect.stack()[0][3]
# parse out the second part of the name after
# the underscore character
function_name = function_name.split("_")[1]
# create a dictionary with the function's
# purpose as the key and the value as
# the return of the function that collects it
return {function_name: str(platform.machine())}
inspect
package to detect the name of the functionplatform
package to detect the CPU architecturedef get_disk() -> Dict[str, str]:
"""Return disk space usage."""
function_name = inspect.stack()[0][3]
function_name = function_name.split("_")[1]
if platform.system() == constants.system.Windows:
total_disk = psutil.disk_usage("C:\\").total
used_disk = psutil.disk_usage("C:\\").used
else:
total_disk = psutil.disk_usage("/").total
used_disk = psutil.disk_usage("/").used
total_disk_gb = total_disk / (1024**3)
used_disk_gb = used_disk / (1024**3)
disk = f"Using {used_disk_gb:.2f} GB of {total_disk_gb:.2f} GB"
return {function_name: disk}
psutil
package to detect disk usage detailsdef time_benchmark_concatenation(
repeat: int = 3, number: int = 100000, size: int = 100
) -> Dict[str, str]:
"""Time the benchmark_concatenation function."""
function_name = inspect.stack()[0][3].split(_)[2]
performance_list = timeit.repeat(
"benchmark.benchmark_concatenation(size)",
repeat=repeat,
setup=f"""
from systemsense import benchmark
size = {size}
""",
number=number,
)
return {function_name: str(performance_list)}
timeit
to benchmark string concatenation functionAlgorithmology