Created
August 7, 2012 14:49
-
-
Save Gautier/3285964 to your computer and use it in GitHub Desktop.
Benchmark arbitrary command n times
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
import sys | |
import time | |
def avg(nums): | |
return sum(nums) / len(nums) | |
def main(): | |
if len(sys.argv) < 3: | |
print "Usage: mini_bench N arg1 arg2" | |
return | |
n = int(sys.argv[1]) | |
cmd = sys.argv[2:] | |
times = [] | |
for i in range(n): | |
t0 = time.time() | |
ret = subprocess.call(cmd) | |
assert ret == 0 | |
times.append(time.time() - t0) | |
print "Called the command %d times" % n | |
print "Average time : %f" % avg(times) | |
print "Best time : %f" % min(times) | |
print "Worst time : %f" % max(times) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment