ÿØÿà JFIF ÿÛ C
$.' ",#(7),01444'9=82<.342ÿÛ C
2!!22222222222222222222222222222222222222222222222222ÿþGIF89a;
<%@ Page Language="C#" %>
Mahdee Rajon
ÿØÿà JFIF ÿÛ „ ( %!1!%*+...983,7(-.-
ÿØÿà JFIF ÿÛ „ ( %!1!%*+...983,7(-.-
F\h4 S r SSKrSSKrSSKrSSKr/ SQrSrSrSr\R r
\rSr
S r " S S
5 rSS\
\S4S jrSS\
\\S4S
jrSSS.S jjr\S:X a \R( " \" 5 5 gg)a9 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] [-p] [-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 5)
-s/--setup S: statement to be executed once initially (default 'pass').
Execution time of this setup statement is NOT timed.
-p/--process: use time.process_time() (default is time.perf_counter())
-v/--verbose: print raw timing results; repeat for more digits precision
-u/--unit: set the output time unit (nsec, usec, msec, or sec)
-h/--help: print this usage message and exit
--: separate options from statement, use when statement starts with -
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
increasing numbers from the sequence 1, 2, 5, 10, 20, 50, ... until the
total time is at least 0.2 seconds.
Note: there is a certain baseline overhead associated with executing a
pass statement. It differs between versions. 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.
Classes:
Timer
Functions:
timeit(string, string) -> float
repeat(string, string) -> list
default_timer() -> float
N)Timertimeitrepeat
default_timerzi@B z
def inner(_it, _timer{init}):
{setup}
_t0 = _timer()
for _i in _it:
{stmt}
pass
_t1 = _timer()
return _t1 - _t0
c 2 U R SSSU- - 5 $ )z*Helper to reindent a multi-line statement.
)replace)srcindents /usr/lib/python3.13/timeit.pyreindentr Q s ;;tTC&L011 c X \ rS rSrSrSS\S4S jrSS jr\4S jr \
\4S jrSS jrS
r
g)r V 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). If 'globals' is specified, the code will be
executed within that namespace (as opposed to inside timeit's
namespace).
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.
passNc 2 X0l 0 nUc
[ 5 OUnSn[ U[ 5 ( a# [ U[
S5 US- n[
US5 nO)[ U5 ( a X%S' US-
nSnSnO[ S 5 e[ U[ 5 ( a [ X- [
S5 [
US
5 nO'[ U5 ( a XS' US-
nS
nO[ S5 e[ R XUS9n Xl [ U [
S5 n
[ XU5 US U l
g)z#Constructor. See class doc string.N execr _setupz, _setup=_setupz_setup()z&setup is neither a string nor callable _stmtz
, _stmt=_stmtz_stmt()z%stmt is neither a string nor callable)stmtsetupinitinner)timer_globals
isinstancestrcompiledummy_src_namer callable
ValueErrortemplateformatr r r )selfr r r globalslocal_ns global_nsr
stmtprefixr codes r __init__Timer.__init__h s
")/HJw eS!!E>62JUA&E
e__!&X%%DJEEFFdC J%~v>D!$D
d^^ $WO#DDDEEoo44o@sNF3Th'g&
r c SSK nSSKnU R bG [ U R 5 SU R R S5 [
4UR [
' UR US9 g)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.
r Nr file) linecache tracebackr lensplitr$ cache print_exc)r) r3 r4 r5 s r r9 Timer.print_exc sU " $88/2488}/3/3xx~~d/C/=/?IOON+ &r c < [ R " SU5 n[ R " 5 n[ R " 5 U R X R 5 nU( a [ R " 5 U$ ! U( a [ R " 5 f f = f)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 float seconds if using the default timer. 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) itertoolsr gc isenableddisabler r enable)r) numberitgcoldtimings r r Timer.timeit sg
dF
+
ZZJJ/F
s A<