[Python-checkins] python/dist/src/Lib timeit.py,1.2,1.3
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Wed, 05 Mar 2003 19:02:14 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv20902
Modified Files:
timeit.py
Log Message:
Add notes about baseline overhead, and about different Python
versions. Add -h/--help option to print doc string.
Index: timeit.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/timeit.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** timeit.py 6 Mar 2003 02:32:19 -0000 1.2
--- timeit.py 6 Mar 2003 03:02:10 -0000 1.3
***************
*** 8,12 ****
Command line usage:
! python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [statement]
Options:
--- 8,12 ----
Command line usage:
! python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement]
Options:
***************
*** 16,19 ****
--- 16,20 ----
-t/--time: use time.time() (default on Unix)
-c/--clock: use time.clock() (default on Windows)
+ -h/--help: print this usage message and exit
statement: statement to be timed (default 'pass')
***************
*** 34,42 ****
repeat the timing a few times and use the best time; the -r option is
good for this. On Unix, you can use clock() to measure CPU time.
"""
# To use this module with older versions of Python, the dependency on
# the itertools module is easily removed; in the template, instead of
! # itertools.repeat(None, count), use [None]*count. It's barely slower.
import sys
--- 35,54 ----
repeat the timing a few times and use the best time; the -r option is
good for this. 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 (especially when comparing different versions of
+ Python). The baseline overhead is measured by invoking the program
+ without arguments.
"""
# To use this module with older versions of Python, the dependency on
# the itertools module is easily removed; in the template, instead of
! # itertools.repeat(None, number), use [None]*number. It's barely
! # slower. Note: the baseline overhead, measured by the default
! # invocation, differs for older 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.
import sys
***************
*** 142,150 ****
import getopt
try:
! opts, args = getopt.getopt(args, "n:s:r:tc",
["number=", "setup=", "repeat=",
! "time", "clock"])
except getopt.error, err:
print err
return 2
timer = default_timer
--- 154,163 ----
import getopt
try:
! opts, args = getopt.getopt(args, "n:s:r:tch",
["number=", "setup=", "repeat=",
! "time", "clock", "help"])
except getopt.error, err:
print err
+ print "use -h/--help for command line help"
return 2
timer = default_timer
***************
*** 162,169 ****
if repeat <= 0:
repeat = 1
! if o in ("-t", "time"):
timer = time.time
! if o in ("-c", "clock"):
timer = time.clock
t = Timer(stmt, setup, timer)
if number == 0:
--- 175,185 ----
if repeat <= 0:
repeat = 1
! if o in ("-t", "--time"):
timer = time.time
! if o in ("-c", "--clock"):
timer = time.clock
+ if o in ("-h", "--help"):
+ print __doc__,
+ return 0
t = Timer(stmt, setup, timer)
if number == 0: