O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

timeit

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required