Skip to content

Commit

Permalink
benchmark report script
Browse files Browse the repository at this point in the history
  • Loading branch information
nicku12345 committed Nov 25, 2022
1 parent f1b5367 commit 3a9caee
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
benchmark_results/scripts/* linguist-vendored
93 changes: 93 additions & 0 deletions benchmark_results/scripts/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import os
import tomli
import yaml

script_dir = __file__

def go_up(current_dir, k):
for _ in range(k):
current_dir = os.path.dirname(current_dir)
return current_dir

project_dir = go_up(script_dir, 3)

def get_project_version():
cargo_toml_dir = os.path.join(project_dir, "./Cargo.toml")
with open(cargo_toml_dir, mode="rb") as f:
cargo_toml = tomli.load(f)

return "v" + cargo_toml["package"]["version"]

def get_template():
template_dir = os.path.join(project_dir, "./benchmark_results/template.yml")
with open(template_dir, "r") as f:
template = yaml.safe_load(f)

return template

def get_tag(s):
return "#" + "-".join(s.replace(".","").lower().split())

def generate_benchmark_results():
version = get_project_version()
result_dir = os.path.join(project_dir, f"./benchmark_results/{version}")
plots_dir = os.path.join(result_dir, "./plots")
if os.path.isdir(result_dir):
raise Exception(f"Version {version} already has a report")

os.mkdir(result_dir)
os.mkdir(plots_dir)

template = get_template()

markdown_content = []
table_of_content = []

# Add title
title = template["Title"]
title = title.replace("${version}", version)
tag = get_tag(title)
markdown_content.append("# " + title)

toc_markdown = f"- [{title}]({tag})"
table_of_content.append(toc_markdown)

# Add description
description = template["Description"]
markdown_content.append(description)
markdown_content.append("")

# Add tests
test_markdown_content = []
for benchmark_test in template["Tests"]:
description = template["Tests"][benchmark_test]["Description"]
src_svg_dir = os.path.join(project_dir, f"./target/criterion/{benchmark_test.lower()}/report/lines.svg")
des_svg_dir = os.path.join(plots_dir, f"./{benchmark_test.lower()}.svg")

src_svg = open(src_svg_dir, "r")
des_svg = open(des_svg_dir, "w")
for data in src_svg.readlines():
data = data.replace("<svg ", "<svg style=\"background-color:white\" ")
des_svg.writelines(data)

svg_name = f"{'%20'.join(benchmark_test.lower().split())}.svg"
tag = get_tag(benchmark_test)

content = []
content.append(f"## {benchmark_test}")
content.append(f"**Description**: {description}")
content.append(f"![img](./plots/{svg_name})")
content.append("")

toc_markdown = f" - [{benchmark_test}]({tag})"
table_of_content.append(toc_markdown)

test_markdown_content += content

markdown_content += table_of_content
markdown_content += test_markdown_content

with open(os.path.join(result_dir, "./result.md"), "w") as f:
f.write("\n".join(markdown_content))

generate_benchmark_results()
26 changes: 26 additions & 0 deletions benchmark_results/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Title:
SortedList ${version} - Benchmark Tests and Results
Description:
This benchmark result is generated using Criterion.rs.
Tests:
Binary search random element:
Description:
Given a sorted list containing `n` random i32 numbers, binary searches a random number in the sorted list.
Get random element:
Description:
Given a sorted list containing `n` random i32 numbers, access the sorted list at a random index.
Insert random element:
Description:
Given a sorted list containing `n` random i32 numbers, access the sorted list at a random index.
Remove first element:
Description:
Given a sorted list containing `n` random i32 numbers, remove the first element till empty.
Remove last element:
Description:
Given a sorted list containing `n` random i32 numbers, remove the last element till empty.
Remove middle element:
Description:
Given a sorted list containing `n` random i32 numbers, remove the middle element till empty.
Remove random element:
Description:
Given a sorted list containing `n` random i32 numbers, remove a random element from the list till empty.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion benchmark_results/v0.2.1/plots/get random element.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion benchmark_results/v0.2.1/plots/insert random element.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion benchmark_results/v0.2.1/plots/remove first element.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion benchmark_results/v0.2.1/plots/remove last element.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion benchmark_results/v0.2.1/plots/remove middle element.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion benchmark_results/v0.2.1/plots/remove random element.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 7 additions & 18 deletions benchmark_results/v0.2.1/result.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SortedList v0.2.1 - Benchmark Tests and Results

This benchmark result is generated using Criterion.rs.

- [SortedList v0.2.1 - Benchmark Tests and Results](#sortedlist-v021---benchmark-tests-and-results)
- [Binary search random element](#binary-search-random-element)
- [Get random element](#get-random-element)
Expand All @@ -9,41 +9,30 @@ This benchmark result is generated using Criterion.rs.
- [Remove last element](#remove-last-element)
- [Remove middle element](#remove-middle-element)
- [Remove random element](#remove-random-element)

## Binary search random element

**Description**: Given a sorted list containing `n` random i32 numbers, binary searches a random number in the sorted list.
![img](./plots/binary%20search%20random%20element.svg)

## Get random element

**Description**: Given a sorted list containing `n` random i32 numbers, access the sorted list at a random index.
![img](./plots/get%20random%20element.svg)

## Insert random element

**Description**: Insert `n` random i32 numbers into an empty sorted list.
**Description**: Given a sorted list containing `n` random i32 numbers, access the sorted list at a random index.
![img](./plots/insert%20random%20element.svg)

## Remove first element

**Description**: Given a sorted list containing `n` random i32 numbers,
remove the first element till empty.
**Description**: Given a sorted list containing `n` random i32 numbers, remove the first element till empty.
![img](./plots/remove%20first%20element.svg)

## Remove last element

**Description**: Given a sorted list containing `n` random i32 numbers,
remove the last element till empty.
**Description**: Given a sorted list containing `n` random i32 numbers, remove the last element till empty.
![img](./plots/remove%20last%20element.svg)

## Remove middle element

**Description**: Given a sorted list containing `n` random i32 numbers,
remove the middle element till empty.
**Description**: Given a sorted list containing `n` random i32 numbers, remove the middle element till empty.
![img](./plots/remove%20middle%20element.svg)

## Remove random element
**Description**: Given a sorted list containing `n` random i32 numbers,
remove a random element fomr the list till empty.
![img](./plots/remove%20random%20element.svg)
**Description**: Given a sorted list containing `n` random i32 numbers, remove a random element from the list till empty.
![img](./plots/remove%20random%20element.svg)

0 comments on commit 3a9caee

Please sign in to comment.