~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/core/benchmarks/timer.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

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