rendered paste bodydef runBenchmark(func, args, count, show_top=5):
import time
stat = []
for index in xrange(count):
sys.stdout.write("Run test %s/%s ... " % (1 + index, count))
sys.stdout.flush()
before = time.time()
func(*args)
after = time.time()
stat.append(after-before)
sys.stdout.write("%0.3f\n" % (after-before))
sys.stdout.flush()
# geometric average
average = reduce(operator.mul, stat) ** (1.0/count)
print "Benchmark: best=%.2f average=%.2f worst=%.2f total=%.2f" \
% (min(stat), average, max(stat), sum(stat))