summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorSteven D'Aprano <steve@pearwood.info>2016-08-14 15:27:03 (GMT)
committerSteven D'Aprano <steve@pearwood.info>2016-08-14 15:27:03 (GMT)
commit09f4f711b67a310873a4cb084f7c413ef3addcd3 (patch)
tree6b018c4f8307857aa5cbc25adffa1daaaf5225b2 /Doc/library
parent9171a8b4cea3e7b30e4f2c0a989d7f7b8ffabe73 (diff)
downloadcpython-09f4f711b67a310873a4cb084f7c413ef3addcd3.zip
cpython-09f4f711b67a310873a4cb084f7c413ef3addcd3.tar.gz
cpython-09f4f711b67a310873a4cb084f7c413ef3addcd3.tar.bz2
Issue6422 add autorange method to timeit.Timer
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/timeit.rst19
1 files changed, 17 insertions, 2 deletions
diff --git a/Doc/library/timeit.rst b/Doc/library/timeit.rst
index 57a4834..f046591 100644
--- a/Doc/library/timeit.rst
+++ b/Doc/library/timeit.rst
@@ -100,8 +100,8 @@ The module defines three convenience functions and a public class:
can be controlled by passing a namespace to *globals*.
To measure the execution time of the first statement, use the :meth:`.timeit`
- method. The :meth:`.repeat` method is a convenience to call :meth:`.timeit`
- multiple times and return a list of results.
+ method. The :meth:`.repeat` and :meth:`.autorange` methods are convenience
+ methods to call :meth:`.timeit` multiple times.
The execution time of *setup* is excluded from the overall timed execution run.
@@ -134,6 +134,21 @@ The module defines three convenience functions and a public class:
timeit.Timer('for i in range(10): oct(i)', 'gc.enable()').timeit()
+ .. method:: Timer.autorange(callback=None)
+
+ Automatically determine how many times to call :meth:`.timeit`.
+
+ This is a convenience function that calls :meth:`.timeit` repeatedly
+ so that the total time >= 0.2 second, returning the eventual
+ (number of loops, time taken for that number of loops). It calls
+ :meth:`.timeit` with *number* set to successive powers of ten (10,
+ 100, 1000, ...) up to a maximum of one billion, until the time taken
+ is at least 0.2 second, or the maximum is reached.
+
+ If *callback* is given and is not *None*, it will be called after
+ each trial with two arguments: ``callback(number, time_taken)``.
+
+
.. method:: Timer.repeat(repeat=3, number=1000000)
Call :meth:`.timeit` a few times.