Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
e8577b72
Kaydet (Commit)
e8577b72
authored
Mar 06, 2003
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add notes about baseline overhead, and about different Python
versions. Add -h/--help option to print doc string.
üst
b7ab6004
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
timeit.py
Lib/timeit.py
+22
-6
No files found.
Lib/timeit.py
Dosyayı görüntüle @
e8577b72
...
...
@@ -7,7 +7,7 @@ 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] [-t] [-c] [statement]
python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [
-h] [
statement]
Options:
-n/--number N: how many times to execute 'statement' (default: see below)
...
...
@@ -15,6 +15,7 @@ Options:
-s/--setup S: statements executed once before 'statement' (default 'pass')
-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')
A multi-line statement may be given by specifying each line as a
...
...
@@ -33,11 +34,22 @@ other processes running on the same computer may interfere with the
timing. The best thing to do when accurate timing is necessary is to
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, count), use [None]*count. It's barely slower.
# 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
import
math
...
...
@@ -141,11 +153,12 @@ def main(args=None):
args
=
sys
.
argv
[
1
:]
import
getopt
try
:
opts
,
args
=
getopt
.
getopt
(
args
,
"n:s:r:tc"
,
opts
,
args
=
getopt
.
getopt
(
args
,
"n:s:r:tc
h
"
,
[
"number="
,
"setup="
,
"repeat="
,
"time"
,
"clock"
])
"time"
,
"clock"
,
"help"
])
except
getopt
.
error
,
err
:
print
err
print
"use -h/--help for command line help"
return
2
timer
=
default_timer
stmt
=
"
\n
"
.
join
(
args
)
or
"pass"
...
...
@@ -161,10 +174,13 @@ def main(args=None):
repeat
=
int
(
a
)
if
repeat
<=
0
:
repeat
=
1
if
o
in
(
"-t"
,
"time"
):
if
o
in
(
"-t"
,
"
--
time"
):
timer
=
time
.
time
if
o
in
(
"-c"
,
"clock"
):
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
:
# determine number so that 0.2 <= total time < 2.0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment