Apr
7
7
Here’s a sample I wrote and find very useful for quick performance tests of python functions.
Python
-
import timing
-
from datetime import datetime
-
def timeit(fn):
-
def wrapper(*args, *kw):
-
timing.start()
-
fn(*args, **kw)
-
timing.finish()
-
f = open("timing.csv", "a")
-
f.write("%s,%s,%d\n"%(datetime.now(), fn.__name__, timing.micro()))
-
f.flush()
-
f.close()
-
return wrapper
You can then import it to OpenOffice Calculator or MS Excel and do some fancy charts or whatever ![]()
Note that this function is using disk I/O so by itself it is also causing some overhead (especially for functions called multiple times per second).
Obviously it’s not thread safe.

