@@ -69,13 +69,14 @@ class BenchmarkStats:
69
69
@classmethod
70
70
def from_list (
71
71
cls ,
72
- times_ns : list [float ],
72
+ times_per_round_ns : list [float ],
73
73
* ,
74
74
rounds : int ,
75
75
iter_per_round : int ,
76
76
warmup_iters : int ,
77
77
total_time : float ,
78
78
) -> BenchmarkStats :
79
+ times_ns = [t / iter_per_round for t in times_per_round_ns ]
79
80
stdev_ns = stdev (times_ns ) if len (times_ns ) > 1 else 0
80
81
mean_ns = mean (times_ns )
81
82
if len (times_ns ) > 1 :
@@ -129,20 +130,20 @@ def run_benchmark(
129
130
out = fn (* args , ** kwargs )
130
131
131
132
# Warmup
132
- times_ns : list [float ] = []
133
+ times_per_round_ns : list [float ] = []
133
134
warmup_start = start = perf_counter_ns ()
134
135
while True :
135
136
start = perf_counter_ns ()
136
137
fn (* args , ** kwargs )
137
138
end = perf_counter_ns ()
138
- times_ns .append (end - start )
139
+ times_per_round_ns .append (end - start )
139
140
if end - warmup_start > config .warmup_time_ns :
140
141
break
141
142
142
143
# Round sizing
143
- warmup_mean_ns = mean (times_ns )
144
- warmup_iters = len (times_ns )
145
- times_ns .clear ()
144
+ warmup_mean_ns = mean (times_per_round_ns )
145
+ warmup_iters = len (times_per_round_ns )
146
+ times_per_round_ns .clear ()
146
147
iter_per_round = (
147
148
int (ceil (config .min_round_time_ns / warmup_mean_ns ))
148
149
if warmup_mean_ns <= config .min_round_time_ns
@@ -163,7 +164,7 @@ def run_benchmark(
163
164
for _ in iter_range :
164
165
fn (* args , ** kwargs )
165
166
end = perf_counter_ns ()
166
- times_ns .append (end - start )
167
+ times_per_round_ns .append (end - start )
167
168
168
169
if end - run_start > config .max_time_ns :
169
170
# TODO: log something
@@ -172,7 +173,7 @@ def run_benchmark(
172
173
total_time = (benchmark_end - run_start ) / 1e9
173
174
174
175
stats = BenchmarkStats .from_list (
175
- times_ns ,
176
+ times_per_round_ns ,
176
177
rounds = rounds ,
177
178
total_time = total_time ,
178
179
iter_per_round = iter_per_round ,
@@ -240,12 +241,12 @@ def _print_benchmark_table(self) -> None:
240
241
241
242
for bench in self .benchmarks :
242
243
rsd = bench .stats .stdev_ns / bench .stats .mean_ns
243
- rsd_text = Text (f"{ rsd * 100 :.1f} %" )
244
+ rsd_text = Text (f"{ rsd * 100 :.1f} %" )
244
245
if rsd > 0.1 :
245
246
rsd_text .stylize ("red bold" )
246
247
table .add_row (
247
248
escape (bench .name ),
248
- f"{ bench .stats .min_ns / bench .stats .iter_per_round :,.0f} ns" ,
249
+ f"{ bench .stats .min_ns / bench .stats .iter_per_round :,.0f} ns" ,
249
250
rsd_text ,
250
251
f"{ bench .stats .total_time :,.2f} s" ,
251
252
f"{ bench .stats .iter_per_round * bench .stats .rounds :,} " ,
0 commit comments