Skip to Content
Python: Essential Reference, Third Edition
book

Python: Essential Reference, Third Edition

by David Beazley
February 2006
Intermediate to advanced content levelIntermediate to advanced
648 pages
14h 53m
English
Sams
Content preview from Python: Essential Reference, Third Edition

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python: Essential Reference

Python: Essential Reference

David M. Beazley

Publisher Resources

ISBN: 0672328623Purchase book