Loading [MathJax]/extensions/TeX/AMSsymbols.js

Wednesday, December 25, 2013

Benchmark functions in Python

This is a function to benchmark functions in Python using decorators, so that you can use it non-intrusively with your current code, just adding the decorator operator @ to the definition of your function. Feel free to modify it with higher resolution time functions.


def bench(f):
def inner(*args, **kwargs):
from time import time
begin = time()
result = f(*args, **kwargs)
end = time()
print "Time elapsed: %d ms" % (end - begin)
return result
return inner
view raw bench.py hosted with ❤ by GitHub

No comments:

Post a Comment