Skip to content

Commit adbbaba

Browse files
committed
Added an example for timeit.timeit with callable arguments
1 parent 874809e commit adbbaba

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Doc/library/timeit.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,17 @@ This can be achieved from the :ref:`python-interface` with::
4646

4747

4848
Note however that :mod:`timeit` will automatically determine the number of
49-
repetitions only when the command-line interface is used. In the
50-
:ref:`timeit-examples` section you can find more advanced examples.
49+
repetitions only when the command-line interface is used.
50+
51+
:mod:`timeit` also takes a callable for the statement and setup parameters::
52+
53+
>>> timeit.timeit(lambda: "-".join(map(str, range(100))), number=10000)
54+
0.19665591977536678
55+
>>> import time
56+
>>> timeit.timeit(lambda: "-".join(map(str, range(100))), setup=lambda: time.sleep(1), number=10000)
57+
0.19662280194461346
58+
59+
In the :ref:`timeit-examples` section you can find more advanced examples.
5160

5261

5362
.. _python-interface:

0 commit comments

Comments
 (0)