MCPcopy Index your code
hub / github.com/RustPython/RustPython / autorange

Method autorange

Lib/timeit.py:209–228  ·  view source on GitHub ↗

Return the number of loops and time taken so that total time >= 0.2. 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

(self, callback=None)

Source from the content-addressed store, hash-verified

207 return r
208
209 def autorange(self, callback=None):
210 """Return the number of loops and time taken so that total time >= 0.2.
211
212 Calls the timeit method with increasing numbers from the sequence
213 1, 2, 5, 10, 20, 50, ... until the time taken is at least 0.2
214 second. Returns (number, time_taken).
215
216 If *callback* is given and is not None, it will be called after
217 each trial with two arguments: ``callback(number, time_taken)``.
218 """
219 i = 1
220 while True:
221 for j in 1, 2, 5:
222 number = i * j
223 time_taken = self.timeit(number)
224 if callback:
225 callback(number, time_taken)
226 if time_taken >= 0.2:
227 return (number, time_taken)
228 i *= 10
229
230
231def 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