diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-10-23 12:17:05 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-10-23 12:17:05 (GMT) |
commit | d3ff784f2d6ffaeee0e9aa1999d2e8ceed47ae82 (patch) | |
tree | 2198560cad1ef6289313a9b808997c803ebe03db /Lib/timeit.py | |
parent | f8d7d41507d8c0855b58c9be14011381d03c5cde (diff) | |
download | cpython-d3ff784f2d6ffaeee0e9aa1999d2e8ceed47ae82.zip cpython-d3ff784f2d6ffaeee0e9aa1999d2e8ceed47ae82.tar.gz cpython-d3ff784f2d6ffaeee0e9aa1999d2e8ceed47ae82.tar.bz2 |
Issue #28469: timeit now uses the sequence 1, 2, 5, 10, 20, 50,... instead
of 1, 10, 100,... for autoranging.
Diffstat (limited to 'Lib/timeit.py')
-rw-r--r-- | Lib/timeit.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/Lib/timeit.py b/Lib/timeit.py index 0b5061f..38c2b1f 100644 --- a/Lib/timeit.py +++ b/Lib/timeit.py @@ -208,22 +208,23 @@ class Timer: def autorange(self, callback=None): """Return the number of loops so that total time >= 0.2. - Calls the timeit method 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. - Returns ``(number, time_taken)``. + Calls the timeit method with increasing numbers from the sequence + 1, 2, 5, 10, 20, 50, ... until the time taken is at least 0.2 + second. Returns (number, time_taken). If *callback* is given and is not None, it will be called after each trial with two arguments: ``callback(number, time_taken)``. """ - for i in range(0, 10): - number = 10**i - time_taken = self.timeit(number) - if callback: - callback(number, time_taken) - if time_taken >= 0.2: - break - return (number, time_taken) + i = 1 + while True: + for j in 1, 2, 5: + number = i * j + time_taken = self.timeit(number) + if callback: + callback(number, time_taken) + if time_taken >= 0.2: + return (number, time_taken) + i *= 10 def timeit(stmt="pass", setup="pass", timer=default_timer, number=default_number, globals=None): |