-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeed_report.py
78 lines (61 loc) · 2.32 KB
/
speed_report.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
75
76
77
78
import matplotlib.pyplot as plt
from typing import Dict, List, Tuple
def parse_benchmark_results(file_path: str) -> Dict[str, List[Tuple[int, float, bool]]]:
"""
Parse benchmark results from a file.
Args:
file_path: Path to the benchmark results file.
Returns:
A dictionary where keys are algorithm names and values are lists of tuples (file_size, execution_time).
"""
with open(file_path, "r") as f:
lines = f.readlines()
lines = lines[1:] # Skip the header line
results: Dict[str, List[Tuple[int, float, bool]]] = {}
for line in lines:
parts = line.strip().split()
if len(parts) == 4:
algorithm = parts[0]
size = int(parts[1])
time = float(parts[2])
reread = parts[3] == "1"
if algorithm not in results:
results[algorithm] = []
results[algorithm].append((size, time, reread))
return results
def plot_results(
results: Dict[str, List[Tuple[int, float, bool]]], reread: bool
) -> None:
"""
Plot the benchmark results.
Args:
results: A dictionary where keys are algorithm names and values are lists of tuples (file_size, execution_time).
reread: Boolean indicating whether to plot results for REREAD_ON_QUERY=True or False.
"""
plt.figure(figsize=(10, 6))
for algorithm, data in results.items():
data = sorted(data)
relevant_data = [
(size, time) for size, time, reread_flag in data if reread_flag == reread
]
if relevant_data:
sizes, times = zip(*relevant_data)
plt.plot(
sizes,
times,
marker="o" if reread else "x",
label=f"{algorithm} ({'reread' if reread else 'no reread'})",
)
plt.xlabel("File Size")
plt.ylabel("Execution Time (s)")
plt.title(
f"Execution Time vs. File Size for Different Algorithms ({'reread' if reread else 'no reread'})"
)
plt.legend()
plt.grid(True)
plt.savefig(f"benchmark_chart_{'reread' if reread else 'no_reread'}.png")
plt.show()
if __name__ == "__main__":
benchmark_results = parse_benchmark_results("benchmark_results.txt")
plot_results(benchmark_results, reread=True)
plot_results(benchmark_results, reread=False)