@@ -196,7 +196,7 @@ def _as_int(value):
196
196
197
197
198
198
class BenchRunner (object ):
199
- def __init__ (self , bench_file , bench_args = None , iterations = 1 , warmup = - 1 , warmup_runs = 0 , startup = False ):
199
+ def __init__ (self , bench_file , bench_args = None , iterations = 1 , warmup = - 1 , warmup_runs = 0 , startup = None ):
200
200
assert isinstance (iterations , int ), \
201
201
"BenchRunner iterations argument must be an int, got %s instead" % iterations
202
202
assert isinstance (warmup , int ), \
@@ -276,25 +276,31 @@ def run(self):
276
276
report_startup = GRAALPYTHON and self .startup and __graalpython__ .startup_nano != - 1
277
277
278
278
bench_func = self ._get_attr (ATTR_BENCHMARK )
279
- startup = - 1
279
+ startup_ns = - 1
280
+ early_warmup_ns = - 1
281
+ late_warmup_ns = - 1
280
282
durations = []
281
283
if bench_func and hasattr (bench_func , '__call__' ):
282
284
if self .warmup_runs :
283
285
print ("### (pre)warming up for %s iterations ... " % self .warmup_runs )
284
286
for _ in range (self .warmup_runs ):
285
287
bench_func (* args )
286
288
cur_time_nano = monotonic_ns ()
287
- if report_startup and startup == - 1 :
288
- startup = cur_time_nano - __graalpython__ .startup_nano
289
+ if report_startup and startup_ns == - 1 :
290
+ startup_ns = cur_time_nano - __graalpython__ .startup_nano
289
291
self ._call_attr (ATTR_CLEANUP , * args )
290
292
291
293
for iteration in range (self .iterations ):
292
294
start = time ()
293
295
bench_func (* args )
294
296
cur_time_nano = monotonic_ns ()
295
297
duration = time () - start
296
- if report_startup and startup == - 1 :
297
- startup = cur_time_nano - __graalpython__ .startup_nano
298
+ if report_startup and startup_ns == - 1 and iteration == self .startup [0 ] - 1 :
299
+ startup_ns = cur_time_nano - __graalpython__ .startup_nano
300
+ if report_startup and early_warmup_ns == - 1 and iteration == self .startup [1 ] - 1 :
301
+ early_warmup_ns = cur_time_nano - __graalpython__ .startup_nano
302
+ if report_startup and late_warmup_ns == - 1 and iteration == self .startup [2 ] - 1 :
303
+ late_warmup_ns = cur_time_nano - __graalpython__ .startup_nano
298
304
durations .append (duration )
299
305
duration_str = "%.3f" % duration
300
306
self ._call_attr (ATTR_CLEANUP , * args )
@@ -324,7 +330,9 @@ def run(self):
324
330
# summary
325
331
# We can do that only on Graalpython
326
332
if report_startup :
327
- print ("### STARTUP duration: %.3f s" % (startup / 10e9 ))
333
+ print ("### STARTUP at iteration: %d, duration: %.3f" % (self .startup [0 ], startup_ns / 1e9 ))
334
+ print ("### EARLY WARMUP at iteration: %d, duration: %.3f" % (self .startup [1 ], early_warmup_ns / 1e9 ))
335
+ print ("### LATE WARMUP at iteration: %d, duration: %.3f" % (self .startup [2 ], late_warmup_ns / 1e9 ))
328
336
if self ._run_once :
329
337
print ("### SINGLE RUN duration: %.3f s" % durations [0 ])
330
338
else :
@@ -359,7 +367,7 @@ def run_benchmark(args):
359
367
warmup = - 1
360
368
warmup_runs = 0
361
369
iterations = 1
362
- startup = False
370
+ startup = None
363
371
bench_file = None
364
372
bench_args = []
365
373
paths = []
@@ -385,8 +393,12 @@ def run_benchmark(args):
385
393
elif arg .startswith ("--warmup-runs" ):
386
394
warmup_runs = _as_int (arg .split ("=" )[1 ])
387
395
388
- elif arg == '-s' or arg == '--startup' :
389
- startup = True
396
+ elif arg .startswith ('--startup' ):
397
+ try :
398
+ itrs = arg .split ("=" )[1 ].split ("," )
399
+ startup = (int (itrs [0 ]), int (itrs [1 ]), int (itrs [2 ]))
400
+ except :
401
+ raise TypeError ("incorrect argument; must be in form of '-s 1,10,100'" )
390
402
391
403
elif arg == '-p' :
392
404
i += 1
@@ -400,6 +412,9 @@ def run_benchmark(args):
400
412
bench_args .append (arg )
401
413
i += 1
402
414
415
+ if startup and iterations < max (startup ):
416
+ print ("### WARNING: you've specified less iterations than required to measure the startup" )
417
+
403
418
# set the paths if specified
404
419
print (_HRULE )
405
420
sys .path .append (os .path .split (bench_file )[0 ])
0 commit comments