17
17
"""measure the runtime of a command by repeatedly running it.
18
18
"""
19
19
20
+ from __future__ import print_function
21
+
20
22
import time
21
23
import subprocess
22
24
import sys
23
25
24
26
devnull = open ('/dev/null' , 'w' )
25
27
26
28
def run (cmd , repeat = 10 ):
27
- print 'sampling:' ,
29
+ print ( 'sampling:' , end = ' ' )
28
30
sys .stdout .flush ()
29
31
30
32
samples = []
@@ -33,10 +35,10 @@ def run(cmd, repeat=10):
33
35
subprocess .call (cmd , stdout = devnull , stderr = devnull )
34
36
end = time .time ()
35
37
dt = (end - start ) * 1000
36
- print '%dms' % int (dt ),
38
+ print ( '%dms' % int (dt ), end = ' ' )
37
39
sys .stdout .flush ()
38
40
samples .append (dt )
39
- print
41
+ print ()
40
42
41
43
# We're interested in the 'pure' runtime of the code, which is
42
44
# conceptually the smallest time we'd see if we ran it enough times
@@ -45,10 +47,10 @@ def run(cmd, repeat=10):
45
47
# Also print how varied the outputs were in an attempt to make it
46
48
# more obvious if something has gone terribly wrong.
47
49
err = sum (s - best for s in samples ) / float (len (samples ))
48
- print 'estimate: %dms (mean err %.1fms)' % (best , err )
50
+ print ( 'estimate: %dms (mean err %.1fms)' % (best , err ) )
49
51
50
52
if __name__ == '__main__' :
51
53
if len (sys .argv ) < 2 :
52
- print 'usage: measure.py command args...'
54
+ print ( 'usage: measure.py command args...' )
53
55
sys .exit (1 )
54
56
run (cmd = sys .argv [1 :])
0 commit comments