February 2006
Intermediate to advanced
648 pages
14h 53m
English
The timeit module is used to time simple Python code.
Timer ([statement [, setup [, timer]]])
Creates a Timer object. statement is a string containing a Python statement to be timed. setup is an optional string containing a Python statement that is executed prior to the timing of statement. timer is a platform-specific timing function such as time.time() or time.clock() in the time module. Normally, this does not need to be supplied.
An instance, t, of Timer has the following methods:
t.print_exc([file])
Prints execution information for exceptions that occur in timed code. To use this, enclose the timeit() method in a try block and use print_exc in an except clause.
t.repeat([repeat [, number]))
Executes the timeit() method multiple ...