Files
canonical-stuff/benchmark.py

37 lines
926 B
Python

# copyright: Canonical
"Run the bench cases (remote to local)."
import datetime
import subprocess
from pathlib import Path
from loguru import logger as log
def run_single_bench(
runnum,
test_case,
files_type,
source,
target,
results,
):
log.info(f"Syncing {runnum} {test_case} {files_type}")
start = datetime.datetime.now()
subprocess.run(
[
"rsync",
"-a",
f"{source}",
f"{target}",
],
capture_output=True,
# shell=True,
)
time = datetime.datetime.now() - start
size = sum(f.stat().st_size for f in Path(target).glob("**/*") if f.is_file())
size_MB = size / 1000 / 1000 / 8
speed = size_MB / time.total_seconds()
log.info(f"{files_type} - {speed} MB/s")
subprocess.run(["rm", "-rf", target])
results.add([runnum, test_case, files_type, speed, time.total_seconds(), size_MB])