-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_visual.py
More file actions
166 lines (148 loc) · 5.06 KB
/
benchmark_visual.py
File metadata and controls
166 lines (148 loc) · 5.06 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python3
"""
Generate benchmark visualization for B-FAST
Generates benchmark_chart.png with hybrid mode results
"""
import matplotlib.pyplot as plt
def generate_chart():
"""Generate benchmark_chart.png (hybrid mode results)"""
plt.style.use("seaborn-v0_8-darkgrid")
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(16, 12))
fig.suptitle("B-FAST Performance Benchmarks", fontsize=20, fontweight="bold")
# 1. Simple Objects (10k) - Speed
categories = ["B-FAST", "orjson", "JSON"]
times = [4.83, 8.19, 12.0]
colors = ["#2ecc71", "#3498db", "#e74c3c"]
bars1 = ax1.bar(
categories, times, color=colors, alpha=0.8, edgecolor="black", linewidth=1.5
)
ax1.set_ylabel("Time (ms)", fontsize=12, fontweight="bold")
ax1.set_title(
"Simple Objects (10,000) - Encoding Speed", fontsize=14, fontweight="bold"
)
ax1.set_ylim(0, max(times) * 1.2)
for i, (bar, time) in enumerate(zip(bars1, times)):
height = bar.get_height()
ax1.text(
bar.get_x() + bar.get_width() / 2.0,
height,
f"{time:.2f}ms",
ha="center",
va="bottom",
fontsize=11,
fontweight="bold",
)
if i == 0:
ax1.text(
bar.get_x() + bar.get_width() / 2.0,
height * 1.1,
"1.7x faster\nthan orjson",
ha="center",
va="bottom",
fontsize=10,
color="green",
fontweight="bold",
)
# 2. Large Objects (100k) on 100 Mbps Network
categories = ["B-FAST+LZ4", "orjson", "JSON"]
times = [1457, 4898, 5478]
colors = ["#2ecc71", "#3498db", "#e74c3c"]
bars2 = ax2.bar(
categories, times, color=colors, alpha=0.8, edgecolor="black", linewidth=1.5
)
ax2.set_ylabel("Time (ms)", fontsize=12, fontweight="bold")
ax2.set_title(
"Large Objects (100k) - 100 Mbps Network", fontsize=14, fontweight="bold"
)
ax2.set_ylim(0, max(times) * 1.2)
for i, (bar, time) in enumerate(zip(bars2, times)):
height = bar.get_height()
ax2.text(
bar.get_x() + bar.get_width() / 2.0,
height,
f"{time:.0f}ms",
ha="center",
va="bottom",
fontsize=11,
fontweight="bold",
)
if i == 0:
ax2.text(
bar.get_x() + bar.get_width() / 2.0,
height * 1.1,
"3.4x faster\nthan orjson",
ha="center",
va="bottom",
fontsize=10,
color="green",
fontweight="bold",
)
# 3. NumPy Array (8MB)
categories = ["B-FAST", "orjson", "JSON"]
times = [3.29, 46.34, 318.21]
colors = ["#2ecc71", "#3498db", "#e74c3c"]
bars3 = ax3.bar(
categories, times, color=colors, alpha=0.8, edgecolor="black", linewidth=1.5
)
ax3.set_ylabel("Time (ms)", fontsize=12, fontweight="bold")
ax3.set_title("NumPy Array (8MB) - Encoding Speed", fontsize=14, fontweight="bold")
ax3.set_yscale("log")
for i, (bar, time) in enumerate(zip(bars3, times)):
height = bar.get_height()
ax3.text(
bar.get_x() + bar.get_width() / 2.0,
height,
f"{time:.1f}ms",
ha="center",
va="bottom",
fontsize=11,
fontweight="bold",
)
if i == 0:
ax3.text(
bar.get_x() + bar.get_width() / 2.0,
height * 2,
"14x faster\nthan orjson",
ha="center",
va="bottom",
fontsize=10,
color="green",
fontweight="bold",
)
# 4. Payload Size
categories = ["B-FAST+LZ4", "B-FAST", "orjson", "JSON"]
sizes = [5.75, 45.11, 55.29, 59.11]
colors = ["#27ae60", "#2ecc71", "#3498db", "#e74c3c"]
bars4 = ax4.bar(
categories, sizes, color=colors, alpha=0.8, edgecolor="black", linewidth=1.5
)
ax4.set_ylabel("Size (MB)", fontsize=12, fontweight="bold")
ax4.set_title("Payload Size (100k Large Objects)", fontsize=14, fontweight="bold")
ax4.set_ylim(0, max(sizes) * 1.2)
for i, (bar, size) in enumerate(zip(bars4, sizes)):
height = bar.get_height()
ax4.text(
bar.get_x() + bar.get_width() / 2.0,
height,
f"{size:.1f}MB",
ha="center",
va="bottom",
fontsize=11,
fontweight="bold",
)
if i == 0:
ax4.text(
bar.get_x() + bar.get_width() / 2.0,
height * 1.1,
"90% smaller\nthan orjson",
ha="center",
va="bottom",
fontsize=10,
color="green",
fontweight="bold",
)
plt.tight_layout()
plt.savefig("benchmark_chart.png", dpi=150, bbox_inches="tight")
print("✅ benchmark_chart.png generated")
if __name__ == "__main__":
generate_chart()