Ticket #3704: timer.py

File timer.py, 440 bytes (added by thijs, 7 years ago)

timer benchmark utility from source:branches/cdefer-2245-4/doc/core/benchmarks (#2245)

Line 
1"""
2Helper stuff for benchmarks
3"""
4
5import gc
6gc.disable()
7print 'Disabled GC'
8
9def timeit(func, iter = 1000, *args, **kwargs):
10    """
11    timeit(func, iter = 1000 *args, **kwargs) -> elapsed time
12   
13    calls func iter times with args and kwargs, returns time elapsed
14    """
15
16    from time import time as currentTime
17    r = range(iter)
18    t = currentTime()
19    for i in r:
20        func(*args, **kwargs)
21    return currentTime() - t