Skip to content

Instantly share code, notes, and snippets.

@yassu
Created April 26, 2014 08:21
Show Gist options
  • Save yassu/11314751 to your computer and use it in GitHub Desktop.
Save yassu/11314751 to your computer and use it in GitHub Desktop.
import timeit as _timeit
from math import sqrt as _sqrt
def timer_test(s_processing, s_pretreatment, repeat=100):
"""
print minimam, max, average, and unbiased of spend times.
"""
t = _timeit.Timer(s_processing, s_pretreatment)
times = t.repeat(repeat)
l = len(times)
ave = sum(times)/len(times)
m = min(times)
M = max(times)
variance = _sqrt(sum([(time - ave)*(time-ave) for time in times])/(len(times)-1))
out = ''
out += 'average: {}\n'.format(ave)
out += 'min : {}\n'.format(m)
out += 'max : {}\n'.format(M)
out += 'unbiased variance: {}'.format(variance)
print(out)
if __name__ == '__main__':
s_processing = 'math.sin(10)'
s_pretreatment = 'import math'
test(s_processing, s_pretreatment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment