mirror of
https://github.com/python/cpython.git
synced 2025-11-03 19:34:08 +00:00
add a note about accessing user-defined functions with an import statement
in the setup parameter
This commit is contained in:
parent
3ec4dfd812
commit
a30dffbb53
1 changed files with 17 additions and 0 deletions
|
|
@ -193,3 +193,20 @@ missing and present object attributes.
|
||||||
>>> print "%.2f usec/pass" % (1000000 * t.timeit(number=100000)/100000)
|
>>> print "%.2f usec/pass" % (1000000 * t.timeit(number=100000)/100000)
|
||||||
3.15 usec/pass
|
3.15 usec/pass
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
|
To give the \module{timeit} module access to functions you
|
||||||
|
define, you can pass a \code{setup} parameter which contains an import
|
||||||
|
statement:
|
||||||
|
|
||||||
|
\begin{verbatim}
|
||||||
|
def test():
|
||||||
|
"Stupid test function"
|
||||||
|
L = []
|
||||||
|
for i in range(100):
|
||||||
|
L.append(i)
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
from timeit import Timer
|
||||||
|
t = Timer("test()", "from __main__ import test")
|
||||||
|
print t.timeit()
|
||||||
|
\end{verbatim}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue