~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to doc/benchmarks/timer.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-01-16 19:56:10 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060116195610-ykmxbia4mnnod9o2
Tags: 2.1.0-0ubuntu2
debian/copyright: Include copyright for python 2.3; some 2.3 files
are included in the upstream tarball, but not in the binary packages.

Show diffs side-by-side

added added

removed removed

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