cpython: 424eb46f7f3a (original) (raw)

Mercurial > cpython

changeset 102651:424eb46f7f3a

Issue6422 add autorange method to timeit.Timer

Steven D'Aprano steve@pearwood.info
date Mon, 15 Aug 2016 01:27:03 +1000
parents e527715bd0b3
children 40b13da7f0f8
files Doc/library/timeit.rst Lib/test/test_timeit.py Lib/timeit.py
diffstat 3 files changed, 69 insertions(+), 13 deletions(-)[+] [-] Doc/library/timeit.rst 19 Lib/test/test_timeit.py 22 Lib/timeit.py 41

line wrap: on

line diff

--- a/Doc/library/timeit.rst +++ b/Doc/library/timeit.rst @@ -100,8 +100,8 @@ The module defines three convenience fun can be controlled by passing a namespace to globals. To measure the execution time of the first statement, use the :meth:.timeit

@@ -134,6 +134,21 @@ The module defines three convenience fun timeit.Timer('for i in range(10): oct(i)', 'gc.enable()').timeit()

+

+

+

+ + .. method:: Timer.repeat(repeat=3, number=1000000) Call :meth:.timeit a few times.

--- a/Lib/test/test_timeit.py +++ b/Lib/test/test_timeit.py @@ -354,6 +354,28 @@ class TestTimeit(unittest.TestCase): s = self.run_main(switches=['-n1', '1/0']) self.assert_exc_string(error_stringio.getvalue(), 'ZeroDivisionError')

+

+

+ if name == 'main': unittest.main()

--- a/Lib/timeit.py +++ b/Lib/timeit.py @@ -207,6 +207,26 @@ class Timer: r.append(t) return r

+

+

+ def timeit(stmt="pass", setup="pass", timer=default_timer, number=default_number, globals=None): """Convenience function to create Timer object and call timeit method.""" @@ -295,17 +315,16 @@ def main(args=None, *, _wrap_timer=None) t = Timer(stmt, setup, timer) if number == 0: # determine number so that 0.2 <= total time < 2.0