All pastes #124209 Raw Edit

Something

public text v1 · immutable
·published 2006-08-09 22:00 UTC
rendered paste body
def 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))