Skip to content

Commit

Permalink
update BENCHMARK.md instead of README.md (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
JIy3AHKO authored Jun 4, 2024
1 parent 53ea401 commit 79f295e
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions benchmark/run_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,34 @@ def get_median(data: List[Dict[str, float]], method_name: str) -> float:
return np.median([row[method_name] for row in data])


def update_benchmark_file(file_path: str, speed_markdown: str, size_markdown: str):
with open(file_path, "r") as f:
readme = f.read()

start_str = "Reading speed:"
end_str = "All measurements are averaged over 1000 iterations. The best result is highlighted in bold."

start = readme.find(start_str)
end = readme.find(end_str)

new_readme = [
readme[:start + len(start_str) + 1],
speed_markdown,
"Mask size:\n",
size_markdown,
readme[end:]
]

new_readme = "\n".join(new_readme)

with open(file_path, "w") as f:
f.write(new_readme)


def test_read_speed(
images_dir: str,
n_iterations: int = 100,
update_readme: bool = False,
update_benchmark: bool = False,
methods: List[str] = None,
):
cv2.setNumThreads(0)
Expand Down Expand Up @@ -238,36 +262,16 @@ def test_read_speed(
size_markdown = draw_md_table(size_table, "KiB")
print(size_markdown)

if update_readme:
with open("README.md", "r") as f:
readme = f.read()

start_str = "Reading speed:"
end_str = "All measurements are averaged over 1000 iterations. The best result is highlighted in bold."

start = readme.find(start_str)
end = readme.find(end_str)

new_readme = [
readme[:start + len(start_str) + 1],
speed_markdown,
"Mask size:\n",
size_markdown,
readme[end:]
]

new_readme = "\n".join(new_readme)

with open("README.md", "w") as f:
f.write(new_readme)
if update_benchmark:
update_benchmark_file('BENCHMARK.md', speed_markdown, size_markdown)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--images-dir", type=str, required=True)
parser.add_argument("--n-iterations", type=int, default=100)
parser.add_argument("--methods", type=str, nargs="+", default=None)
parser.add_argument("--update-readme", action="store_true")
parser.add_argument("--update-benchmark", action="store_true")
args = parser.parse_args()

test_read_speed(args.images_dir, args.n_iterations, args.update_readme, args.methods)
test_read_speed(args.images_dir, args.n_iterations, args.update_benchmark, args.methods)

0 comments on commit 79f295e

Please sign in to comment.