Module Expr Str Import alias Import alias Import alias TryExcept body Import alias handlers ExceptHandler type NameLoad body Assign NameStore NameLoad Assign NameStore ListLoad Str Assign NameStore Str Assign NameStore Num Assign NameStore Num If CompareEq AttributeLoad NameLoad attr Str body Assign NameStore AttributeLoad NameLoad attr orelse Assign NameStore AttributeLoad NameLoad attr Assign NameStore Str FunctionDef arguments args NameParam NameParam defaults body Expr Str Return Call AttributeLoad NameLoad attr Str BinOpAdd Str BinOpMult Str NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str FunctionDef arguments args NameParam NameParam defaults body Expr Call NameLoad Assign NameStore Call NameLoad For NameStore NameLoad body Expr Call NameLoad Assign NameStore Call NameLoad Return BinOpSub NameLoad NameLoad decorator_list Return NameLoad decorator_list ClassDef bases body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam defaults Str Str NameLoad body Expr Str Assign AttributeStore NameLoad attr NameLoad Assign NameStore Dict If Call NameLoad NameLoad NameLoad body Assign NameStore Call NameLoad NameLoad Num If Call NameLoad NameLoad NameLoad body Assign NameStore Call NameLoad NameLoad Num Assign NameStore BinOpMod NameLoad Dict Str Str NameLoad NameLoad orelse If Call NameLoad NameLoad body Assign NameStore BinOpMod NameLoad Dict Str Str NameLoad Str Assign SubscriptStore NameLoad Index Str NameLoad orelse Raise Call NameLoad Str Assign AttributeStore NameLoad attr NameLoad Assign NameStore Call NameLoad NameLoad NameLoad Str Exec NameLoad Call NameLoad NameLoad Assign AttributeStore NameLoad attr SubscriptLoad NameLoad Index Str orelse If Call NameLoad NameLoad body Assign AttributeStore NameLoad attr NameLoad If Call NameLoad NameLoad NameLoad body Assign NameStore NameLoad FunctionDef arguments args defaults body Exec NameLoad Call NameLoad NameLoad decorator_list orelse If UnaryOpNot Call NameLoad NameLoad body Raise Call NameLoad Str Assign AttributeStore NameLoad attr Call NameLoad NameLoad NameLoad orelse Raise Call NameLoad Str decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str Import alias alias If CompareIsNot AttributeLoad NameLoad attr NameLoad body Assign SubscriptStore AttributeLoad NameLoad attr Index NameLoad TupleLoad Call NameLoad AttributeLoad NameLoad attr NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr Str NameLoad Expr Call AttributeLoad NameLoad attr keyword NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str If NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad orelse Assign NameStore BinOpMult ListLoad NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr NameLoad AttributeLoad NameLoad attr If NameLoad body Expr Call AttributeLoad NameLoad attr Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad NameLoad body Expr Str Assign NameStore ListLoad For NameStore Call NameLoad NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Return NameLoad decorator_list decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults Str Str NameLoad NameLoad body Expr Str Return Call AttributeLoad Call NameLoad NameLoad NameLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults Str Str NameLoad NameLoad NameLoad body Expr Str Return Call AttributeLoad Call NameLoad NameLoad NameLoad NameLoad attr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults NameLoad body Expr Str If CompareIs NameLoad NameLoad body Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Slice Num Import alias TryExcept body Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad Str ListLoad Str Str Str Str Str Str Str handlers ExceptHandler type AttributeLoad NameLoad attr name NameStore body Print NameLoad Print Str Return Num Assign NameStore NameLoad Assign NameStore BoolOpOr Call AttributeLoad Str attr NameLoad Str Assign NameStore Num Assign NameStore ListLoad Assign NameStore NameLoad Assign NameStore Num Assign NameStore Num For TupleStore NameStore NameStore NameLoad body If CompareIn NameLoad TupleLoad Str Str body Assign NameStore Call NameLoad NameLoad If CompareIn NameLoad TupleLoad Str Str body Expr Call AttributeLoad NameLoad attr NameLoad If CompareIn NameLoad TupleLoad Str Str body Assign NameStore Call NameLoad NameLoad If CompareLtE NameLoad Num body Assign NameStore Num If CompareIn NameLoad TupleLoad Str Str body Assign NameStore AttributeLoad NameLoad attr If CompareIn NameLoad TupleLoad Str Str body Assign NameStore AttributeLoad NameLoad attr If CompareIn NameLoad TupleLoad Str Str body If NameLoad body AugAssignAdd NameStore Num AugAssignAdd NameStore Num If CompareIn NameLoad TupleLoad Str Str body Print NameLoad Return Num Assign NameStore BoolOpOr Call AttributeLoad Str attr NameLoad Str Import alias Expr Call AttributeLoad AttributeLoad NameLoad attr attr Num AttributeLoad NameLoad attr Assign NameStore Call NameLoad NameLoad NameLoad NameLoad If CompareEq NameLoad Num body For NameStore Call NameLoad Num Num body Assign NameStore BinOpPow Num NameLoad TryExcept body Assign NameStore Call AttributeLoad NameLoad attr NameLoad handlers ExceptHandler body Expr Call AttributeLoad NameLoad attr Return Num If NameLoad body Print BinOpMod Str TupleLoad NameLoad NameLoad NameLoad If CompareGtE NameLoad Num body Break TryExcept body Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad handlers ExceptHandler body Expr Call AttributeLoad NameLoad attr Return Num Assign NameStore Call NameLoad NameLoad If NameLoad body Print Str Call AttributeLoad Str attr ListComp BinOpMod Str TupleLoad NameLoad NameLoad comprehension NameStore NameLoad Print BinOpMod Str NameLoad Assign NameStore BinOpDiv BinOpMult NameLoad Num NameLoad If CompareLt NameLoad Num body Print BinOpMod Str TupleLoad NameLoad NameLoad NameLoad orelse Assign NameStore BinOpDiv NameLoad Num If CompareLt NameLoad Num body Print BinOpMod Str TupleLoad NameLoad NameLoad NameLoad orelse Assign NameStore BinOpDiv NameLoad Num Print BinOpMod Str TupleLoad NameLoad NameLoad NameLoad Return NameLoad decorator_list If CompareEq NameLoad Str body Expr Call AttributeLoad NameLoad attr Call NameLoad
N/A N/A Tool for measuring execution time of small code snippets.

This module avoids a number of common traps for measuring execution
times.  See also Tim Peters' introduction to the Algorithms chapter in
the Python Cookbook, published by O'Reilly.

Library usage: see the Timer class.

Command line usage:
    python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement]

Options:
  -n/--number N: how many times to execute 'statement' (default: see below)
  -r/--repeat N: how many times to repeat the timer (default 3)
  -s/--setup S: statement to be executed once initially (default 'pass')
  -t/--time: use time.time() (default on Unix)
  -c/--clock: use time.clock() (default on Windows)
  -v/--verbose: print raw timing results; repeat for more digits precision
  -h/--help: print this usage message and exit
  statement: statement to be timed (default 'pass')

A multi-line statement may be given by specifying each line as a
separate argument; indented lines are possible by enclosing an
argument in quotes and using leading spaces.  Multiple -s options are
treated similarly.

If -n is not given, a suitable number of loops is calculated by trying
successive powers of 10 until the total time is at least 0.2 seconds.

The difference in default timer function is because on Windows,
clock() has microsecond granularity but time()'s granularity is 1/60th
of a second; on Unix, clock() has 1/100th of a second granularity and
time() is much more precise.  On either platform, the default timer
functions measure wall clock time, not the CPU time.  This means that
other processes running on the same computer may interfere with the
timing.  The best thing to do when accurate timing is necessary is to
repeat the timing a few times and use the best time.  The -r option is
good for this; the default of 3 repetitions is probably enough in most
cases.  On Unix, you can use clock() to measure CPU time.

Note: there is a certain baseline overhead associated with executing a
pass statement.  The code here doesn't try to hide it, but you should
be aware of it.  The baseline overhead can be measured by invoking the
program without arguments.

The baseline overhead differs between Python versions!  Also, to
fairly compare older Python versions to Python 2.3, you may want to
use python -O for the older versions to avoid timing SET_LINENO
instructions.
 N/A gc N/A sys N/A time N/A N/A N/A itertools N/A N/A N/A ImportError N/A N/A itertools None N/A __all__ N/A Timer N/A dummy_src_name <timeit-src> N/A default_number 1000000 N/A default_repeat 3 N/A N/A N/A sys platform win32 N/A N/A default_timer N/A time clock N/A N/A default_timer N/A time time N/A template 
def inner(_it, _timer):
    %(setup)s
    _t0 = _timer()
    for _i in _it:
        %(stmt)s
    _t1 = _timer()
    return _t1 - _t0
 reindent N/A N/A src indent N/A N/A N/A Helper to reindent a multi-line statement. N/A N/A N/A src replace N/A N/A indent N/A _template_func N/A N/A setup func N/A N/A N/A Create a timer function. Used if the "statement" is a callable. inner N/A N/A _it _timer N/A N/A N/A N/A setup N/A _t0 N/A _timer N/A _i _it N/A N/A N/A func N/A _t1 N/A _timer N/A N/A _t1 _t0 N/A N/A inner N/A Timer N/A N/A N/A Class for timing execution speed of small code snippets.

    The constructor takes a statement to be timed, an additional
    statement used for setup, and a timer function.  Both statements
    default to 'pass'; the timer function is platform-dependent (see
    module doc string).

    To measure the execution time of the first statement, use the
    timeit() method.  The repeat() method is a convenience to call
    timeit() multiple times and return a list of results.

    The statements may contain newlines, as long as they don't contain
    multi-line string literals.
     __init__ N/A N/A self stmt setup timer N/A pass pass default_timer N/A N/A Constructor.  See class doc string. N/A N/A self timer timer N/A ns N/A N/A N/A isinstance stmt basestring N/A N/A stmt N/A reindent stmt 8 N/A N/A isinstance setup basestring N/A N/A setup N/A reindent setup 4 N/A src N/A template N/A stmt setup stmt setup N/A N/A N/A callable setup N/A N/A src N/A template N/A stmt setup stmt _setup() N/A N/A ns N/A _setup setup N/A N/A N/A ValueError setup is neither a string nor callable N/A N/A self src src N/A code N/A compile src dummy_src_name exec N/A code N/A globals ns N/A N/A self inner N/A ns N/A inner N/A N/A N/A callable stmt N/A N/A N/A self src None N/A N/A isinstance setup basestring N/A N/A _setup setup setup N/A N/A N/A N/A N/A _setup N/A globals ns N/A N/A N/A N/A N/A callable setup N/A N/A N/A ValueError setup is neither a string nor callable N/A N/A self inner N/A _template_func setup stmt N/A N/A N/A ValueError stmt is neither a string nor callable N/A print_exc N/A N/A self file N/A None N/A N/A Helper to print a traceback from the timed code.

        Typical use:

            t = Timer(...)       # outside the try/except
            try:
                t.timeit(...)    # or t.repeat(...)
            except:
                t.print_exc()

        The advantage over the standard traceback is that source lines
        in the compiled template will be displayed.

        The optional file argument directs where the traceback is
        sent; it defaults to sys.stderr.
         N/A linecache traceback N/A N/A N/A self src None N/A N/A N/A N/A linecache cache N/A dummy_src_name N/A N/A len N/A self src None N/A N/A N/A self src split dummy_src_name N/A N/A N/A traceback print_exc file file N/A timeit N/A N/A self number N/A default_number N/A N/A Time 'number' executions of the main statement.

        To be precise, this executes the setup statement once, and
        then returns the time it takes to execute the main statement
        a number of times, as a float measured in seconds.  The
        argument is the number of times through the loop, defaulting
        to one million.  The main statement, the setup statement and
        the timer function to be used are passed to the constructor.
         N/A itertools N/A N/A it N/A N/A itertools repeat None number N/A N/A it N/A N/A None number N/A gcold N/A N/A gc isenabled N/A N/A N/A gc disable N/A timing N/A N/A self inner it N/A self timer N/A gcold N/A N/A N/A N/A gc enable N/A timing N/A repeat N/A N/A self repeat number N/A default_repeat default_number N/A N/A Call timeit() a few times.

        This is a convenience function that calls the timeit()
        repeatedly, returning a list of results.  The first argument
        specifies how many times to call timeit(), defaulting to 3;
        the second argument specifies the timer argument, defaulting
        to one million.

        Note: it's tempting to calculate mean and standard deviation
        from the result vector and report these.  However, this is not
        very useful.  In a typical case, the lowest value gives a
        lower bound for how fast your machine can run the given code
        snippet; higher values in the result vector are typically not
        caused by variability in Python's speed, but by other
        processes interfering with your timing accuracy.  So the min()
        of the result is probably the only number you should be
        interested in.  After that, you should look at the entire
        vector and apply common sense rather than statistics.
         N/A r N/A N/A i N/A range repeat N/A N/A t N/A N/A self timeit number N/A N/A N/A r append t N/A r N/A N/A timeit N/A N/A stmt setup timer number N/A pass pass default_timer default_number N/A N/A Convenience function to create Timer object and call timeit method. N/A N/A N/A N/A Timer stmt setup timer timeit number N/A repeat N/A N/A stmt setup timer repeat number N/A pass pass default_timer default_repeat default_number N/A N/A Convenience function to create Timer object and call repeat method. N/A N/A N/A N/A Timer stmt setup timer repeat repeat number N/A main N/A N/A args N/A None N/A N/A Main program, used when run as a script.

    The optional argument specifies the command line to be parsed,
    defaulting to sys.argv[1:].

    The return value is an exit code to be passed to sys.exit(); it
    may be None to indicate success.

    When an exception happens during timing, a traceback is printed to
    stderr and the return value is 1.  Exceptions at other times
    (including the template compilation) are not caught.
     N/A N/A args None N/A N/A args N/A N/A sys argv N/A 1 N/A getopt N/A N/A N/A N/A opts args N/A N/A getopt getopt args n:s:r:tcvh N/A number= setup= repeat= time clock verbose help N/A N/A N/A N/A getopt error N/A err N/A N/A err N/A use -h/--help for command line help N/A 2 N/A timer default_timer N/A stmt N/A N/A N/A join args pass N/A number 0 N/A setup N/A N/A repeat default_repeat N/A verbose 0 N/A precision 3 N/A N/A o a opts N/A N/A N/A o N/A -n --number N/A N/A number N/A int a N/A N/A o N/A -s --setup N/A N/A N/A N/A setup append a N/A N/A o N/A -r --repeat N/A N/A repeat N/A int a N/A N/A repeat 0 N/A N/A repeat 1 N/A N/A o N/A -t --time N/A N/A timer N/A time time N/A N/A o N/A -c --clock N/A N/A timer N/A time clock N/A N/A o N/A -v --verbose N/A N/A verbose N/A N/A precision 1 N/A verbose 1 N/A N/A o N/A -h --help N/A N/A __doc__ N/A 0 N/A setup N/A N/A N/A join setup pass N/A os N/A N/A N/A N/A sys path insert 0 N/A os curdir N/A t N/A Timer stmt setup timer N/A N/A number 0 N/A N/A i N/A range 1 10 N/A N/A number N/A 10 i N/A N/A N/A x N/A N/A t timeit number N/A N/A N/A N/A N/A N/A t print_exc N/A 1 N/A verbose N/A N/A N/A %d loops -> %.*g secs N/A number precision x N/A N/A x 0.2 N/A N/A N/A N/A N/A r N/A N/A t repeat repeat number N/A N/A N/A N/A N/A N/A t print_exc N/A 1 N/A best N/A min r N/A verbose N/A N/A raw times: N/A N/A join N/A N/A %.*g N/A precision x N/A x r N/A N/A %d loops, number N/A usec N/A N/A best 1000000.0 number N/A N/A usec 1000 N/A N/A N/A best of %d: %.*g usec per loop N/A repeat precision usec N/A N/A msec N/A usec 1000 N/A N/A msec 1000 N/A N/A N/A best of %d: %.*g msec per loop N/A repeat precision msec N/A N/A sec N/A msec 1000 N/A N/A best of %d: %.*g sec per loop N/A repeat precision sec N/A None N/A N/A N/A __name__ __main__ N/A N/A N/A N/A sys exit N/A main