MCPcopy Index your code
hub / github.com/python/cpython / autorange

Method autorange

Lib/timeit.py:219–239  ·  view source on GitHub ↗

Return the number of loops and time taken so that total time >= target_time (default is 0.2 seconds). Calls the timeit method with increasing numbers from the sequence 1, 2, 5, 10, 20, 50, ... until the target time is reached. Returns (number, time_taken). I

(self, callback=None, target_time=default_target_time)

Source from the content-addressed store, hash-verified

217 return r
218
219 def autorange(self, callback=None, target_time=default_target_time):
220 """Return the number of loops and time taken so that
221 total time >= target_time (default is 0.2 seconds).
222
223 Calls the timeit method with increasing numbers from the sequence
224 1, 2, 5, 10, 20, 50, ... until the target time is reached.
225 Returns (number, time_taken).
226
227 If *callback* is given and is not None, it will be called after
228 each trial with two arguments: ``callback(number, time_taken)``.
229 """
230 i = 1
231 while True:
232 for j in 1, 2, 5:
233 number = i * j
234 time_taken = self.timeit(number)
235 if callback:
236 callback(number, time_taken)
237 if time_taken >= target_time:
238 return (number, time_taken)
239 i *= 10
240
241
242def timeit(stmt="pass", setup="pass", timer=default_timer,

Callers 2

mainFunction · 0.95
autorangeMethod · 0.95

Calls 2

timeitMethod · 0.95
callbackFunction · 0.70

Tested by 1

autorangeMethod · 0.76