Lines Matching +full:repeat +full:- +full:string
1 :mod:`timeit` --- Measure execution time of small code snippets
16 --------------
19 a :ref:`timeit-command-line-interface` as well as a :ref:`callable <python-interface>`
26 --------------
28 The following example shows how the :ref:`timeit-command-line-interface`
31 .. code-block:: sh
33 $ python -m timeit '"-".join(str(n) for n in range(100))'
35 $ python -m timeit '"-".join([str(n) for n in range(100)])'
37 $ python -m timeit '"-".join(map(str, range(100)))'
40 This can be achieved from the :ref:`python-interface` with::
43 >>> timeit.timeit('"-".join(str(n) for n in range(100))', number=10000)
45 >>> timeit.timeit('"-".join([str(n) for n in range(100)])', number=10000)
47 >>> timeit.timeit('"-".join(map(str, range(100)))', number=10000)
51 repetitions only when the command-line interface is used. In the
52 :ref:`timeit-examples` section you can find more advanced examples.
55 .. _python-interface:
58 ----------------
71 .. function:: repeat(stmt='pass', setup='pass', timer=<default timer>, repeat=3, number=1000000)
74 *timer* function and run its :meth:`.repeat` method with the given *repeat*
82 Define a default timer, in a platform-specific manner. On Windows,
97 the timer function is platform-dependent (see the module doc string).
99 or newlines, as long as they don't contain multi-line string literals.
102 method. The :meth:`.repeat` method is a convenience to call :meth:`.timeit`
128 function being measured. If so, GC can be re-enabled as the first
129 statement in the *setup* string. For example::
134 .. method:: Timer.repeat(repeat=3, number=1000000)
164 t.timeit(...) # or t.repeat(...)
173 .. _timeit-command-line-interface:
175 Command-Line Interface
176 ----------------------
180 python -m timeit [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement ...]
186 .. cmdoption:: -n N, --number=N
190 .. cmdoption:: -r N, --repeat=N
192 how many times to repeat the timer (default 3)
194 .. cmdoption:: -s S, --setup=S
198 .. cmdoption:: -t, --time
202 .. cmdoption:: -c, --clock
206 .. cmdoption:: -v, --verbose
208 print raw timing results; repeat for more digits precision
210 .. cmdoption:: -h, --help
214 A multi-line statement may be given by specifying each line as a separate
216 quotes and using leading spaces. Multiple :option:`-s` options are treated
219 If :option:`-n` is not given, a suitable number of loops is calculated by trying
224 the best thing to do when accurate timing is necessary is to repeat
225 the timing a few times and use the best time. The :option:`-r` option is good
235 versions to Python 2.3, you may want to use Python's :option:`!-O`
236 option (see :ref:`Optimizations <using-on-optimizations>`) for
240 .. _timeit-examples:
243 --------
247 .. code-block:: sh
249 $ python -m timeit -s 'text = "sample string"; char = "g"' 'char in text'
251 $ python -m timeit -s 'text = "sample string"; char = "g"' 'text.find(char)'
257 >>> timeit.timeit('char in text', setup='text = "sample string"; char = "g"')
259 >>> timeit.timeit('text.find(char)', setup='text = "sample string"; char = "g"')
265 >>> t = timeit.Timer('char in text', setup='text = "sample string"; char = "g"')
268 >>> t.repeat()
276 .. code-block:: sh
278 $ python -m timeit 'try:' ' str.__nonzero__' 'except AttributeError:' ' pass'
280 $ python -m timeit 'if hasattr(str, "__nonzero__"): pass'
283 $ python -m timeit 'try:' ' int.__nonzero__' 'except AttributeError:' ' pass'
285 $ python -m timeit 'if hasattr(int, "__nonzero__"): pass'