-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_entrypoints.py
74 lines (61 loc) · 2.09 KB
/
benchmark_entrypoints.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import subprocess
import time
from tabulate import tabulate
def run_command(command):
start_time = time.time()
subprocess.run(
command,
shell=True,
# check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
end_time = time.time()
return end_time - start_time
def sort_and_rank_results(results):
"""Sort the results based on execution time and add rank column to each row."""
sorted_results = sorted(results, key=lambda x: float(x[1].rstrip("s")))
ranked_results = [[i + 1] + result for i, result in enumerate(sorted_results)]
return ranked_results
def benchmark_entrypoints():
configurations = [
("Stdlib [baseline], minimum", "emptypt-minimum", False),
("Stdlib [baseline], simple", "emptypt-simple", False),
("msgspec + argh", "emptypt-m-argh", True),
("msgspec + argh (docstring)", "emptypt-m-argh-docstr", True),
("msgspec + click", "emptypt-m-click", False),
("msgspec + typer", "emptypt-m-typer", False),
("msgspec + defopt", "emptypt-m-defopt", True),
("pydantic + argh", "emptypt-p-argh", True),
("pydantic + argh (docstring)", "emptypt-p-argh-docstr", True),
("pydantic + click", "emptypt-p-click", False),
("pydantic + typer", "emptypt-p-typer", False),
("pydantic + defopt", "emptypt-p-defopt", True),
]
results = []
for config, entrypoint, autogenerate in configurations:
execution_time = run_command(entrypoint)
results.append(
[
config,
f"{execution_time:.3f}s",
entrypoint,
"Yes" if autogenerate else "-",
],
)
headers = [
"Rank",
"Configuration",
"Execution Time",
"entrypoint",
"Autogenerate from config",
]
table = tabulate(
sort_and_rank_results(results),
headers=headers,
tablefmt="pipe",
colalign=("left", "right", "left", "center"),
)
print(table)
if __name__ == "__main__":
benchmark_entrypoints()