~certify-web-dev/twisted/certify-staging

« back to all changes in this revision

Viewing changes to doc/benchmarks/timer.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-01-02 19:38:17 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100102193817-jphp464ppwh7dulg
Tags: 9.0.0-1
* python-twisted: Depend on the python-twisted-* 9.0 packages.
* python-twisted: Depend on python-zope.interface only. Closes: #557781.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2007-2009 Twisted Matrix Laboratories.
 
2
# See LICENSE for details.
1
3
 
2
 
"""Helper stuff for things"""
 
4
"""
 
5
Helper stuff for benchmarks.
 
6
"""
3
7
 
4
8
import gc
5
9
gc.disable()
6
10
print 'Disabled GC'
7
11
 
8
12
def timeit(func, iter = 1000, *args, **kwargs):
9
 
    """timeit(func, iter = 1000 *args, **kwargs) -> elapsed time
 
13
    """
 
14
    timeit(func, iter = 1000 *args, **kwargs) -> elapsed time
10
15
    
11
16
    calls func iter times with args and kwargs, returns time elapsed
12
17
    """
13
18
 
14
 
    import time
 
19
    from time import time as currentTime
15
20
    r = range(iter)
16
 
    t = time.time()
 
21
    t = currentTime()
17
22
    for i in r:
18
23
        func(*args, **kwargs)
19
 
    return time.time() - t
 
24
    return currentTime() - t