Skip to content

Commit

Permalink
misc: make benchmark summary more clear
Browse files Browse the repository at this point in the history
All the data is reserved for two decimal places. When the gap of
current pr and master over five percent of the master, we will add ↑ or ↓.

Signed-off-by: Desiki-high <ding_yadong@foxmail.com>
  • Loading branch information
Desiki-high authored and imeoer committed Apr 27, 2023
1 parent 44b70fa commit 944cc69
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
8 changes: 4 additions & 4 deletions misc/benchmark/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ def bench_image(local_registry, insecure_local_registry, image, f: TextIOWrapper
insecure_registry=insecure_local_registry,
)
pull_elapsed, create_elapsed, run_elapsed, image_size, read_amount, read_count = runner.run(bench)
total_elapsed = f"{pull_elapsed + create_elapsed + run_elapsed: .6f}"
pull_elapsed = f"{pull_elapsed: .6f}"
create_elapsed = f"{create_elapsed: .6f}"
run_elapsed = f"{run_elapsed: .6f}"
total_elapsed = f"{pull_elapsed + create_elapsed + run_elapsed: .2f}"
pull_elapsed = f"{pull_elapsed: .2f}"
create_elapsed = f"{create_elapsed: .2f}"
run_elapsed = f"{run_elapsed: .2f}"
line = f"{pull_elapsed},{create_elapsed},{run_elapsed},{total_elapsed},{image_size},{read_amount},{read_count}"
f.writelines(line + "\n")
f.flush()
59 changes: 44 additions & 15 deletions misc/benchmark/benchmark_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,38 @@

FILE_LIST_COMPARE = [
"oci.csv",
"nydus-all-prefetch-master.csv",
"nydus-all-prefetch.csv",
"zran-all-prefetch-master.csv",
"zran-all-prefetch.csv",
"nydus-no-prefetch-master.csv",
"nydus-no-prefetch.csv",
"zran-no-prefetch-master.csv",
"zran-no-prefetch.csv",
"nydus-filelist-prefetch-master.csv",
"nydus-filelist-prefetch.csv"
("nydus-all-prefetch-master.csv", "nydus-all-prefetch.csv"),
("zran-all-prefetch-master.csv", "zran-all-prefetch.csv"),
("nydus-no-prefetch-master.csv", "nydus-no-prefetch.csv"),
("zran-no-prefetch-master.csv", "zran-no-prefetch.csv"),
("nydus-filelist-prefetch-master.csv", "nydus-filelist-prefetch.csv")
]


class BenchmarkSummary:
def __init__(self, mode):
self.mode = mode

def summary(self):
self.prepare_csv()
print("| bench-result | pull-elapsed(s) | create-elapsed(s) | run-elapsed(s) | total-elapsed(s) | image-size(MB) | read-amount(MB) | read-count |")
print("|:-------------|:---------------:|:-----------------:|:--------------:|:----------------:|:--------------:|:---------------:|:----------:|")
if self.mode == "benchmark-result":
self.print_csv_result()
else:
self.print_csv_compare()

def print_csv_result(self):
print("| bench-result | pull(s) | create(s) | run(s) | total(s) | size(MB) | read-amount(MB) | read-count |")
print("|:-------------|:-------:|:---------:|:------:|:--------:|:--------:|:---------------:|:----------:|")
for file in FILE_LIST:
print_csv(file)

def print_csv_compare(self):
for file in FILE_LIST_COMPARE:
print_csv(file)
print("| bench-result(current vs master) | pull(s) | create(s) | run(s) | total(s) | size(MB) | read-amount(MB) | read-count |")
print("|:--------------------------------|:-------:|:---------:|:------:|:--------:|:--------:|:---------------:|:----------:|")
for item in FILE_LIST_COMPARE:
if isinstance(item, str):
print_csv(item)
else:
print_compare(item[0], item[1])

def prepare_csv(self):
"""
Expand All @@ -86,6 +85,36 @@ def print_csv(file: str):
print(f"|{filename}|{pull_elapsed}|{create_elapsed}|{run_elapsed}|{total_elapsed}|{image_size}|{read_amount}|{read_count}|")


def print_compare(file_master: str, file: str):
with open(file, 'r', newline='') as f:
filename = file.rstrip(".csv")
rows = csv.reader(f)
for row in rows:
pull_elapsed, create_elapsed, run_elapsed, total_elapsed, image_size, read_amount, read_count = row
with open(file_master, 'r', newline='') as f:
rows = csv.reader(f)
for row in rows:
pull_elapsed_master, create_elapsed_master, run_elapsed_master, total_elapsed_master, image_size_master, read_amount_master, read_count_master = row
pull_elapsed_compare = compare(pull_elapsed,pull_elapsed_master)
create_elapsed_compare = compare(create_elapsed, create_elapsed_master)
run_elapsed_compare = compare(run_elapsed, run_elapsed_master)
total_elapsed_compare = compare(total_elapsed, total_elapsed_master,True)
image_size_compare = compare(image_size, image_size_master, True)
read_amount_compare = compare(read_amount, read_amount_master, True)
read_count_compare = compare(read_count, read_count_master, True)

print(f"|{filename}|{pull_elapsed_compare}|{create_elapsed_compare}|{run_elapsed_compare}|{total_elapsed_compare}|{image_size_compare}|{read_amount_compare}|{read_count_compare}|")

def compare(data_current: str, data_master: str, compare: bool = False) -> str:
data_current = float(data_current)
data_master = float(data_master)
if abs(data_current - data_master) > data_master * 0.05 and compare:
if data_current > data_master:
return f"{data_current}/{data_master}↑"
else:
return f"{data_current}/{data_master}↓"
return f"{data_current}/{data_master}"

def main():
parser = ArgumentParser()
parser.add_argument(
Expand Down

0 comments on commit 944cc69

Please sign in to comment.