Time 'number' executions of the main statement. To be precise, this executes the setup statement once, and then returns the time it takes to execute the main statement a number of times, as float seconds if using the default timer. The argument is the number of tim
(self, number=default_number)
| 161 | traceback.print_exc(file=file) |
| 162 | |
| 163 | def timeit(self, number=default_number): |
| 164 | """Time 'number' executions of the main statement. |
| 165 | |
| 166 | To be precise, this executes the setup statement once, and |
| 167 | then returns the time it takes to execute the main statement |
| 168 | a number of times, as float seconds if using the default timer. The |
| 169 | argument is the number of times through the loop, defaulting |
| 170 | to one million. The main statement, the setup statement and |
| 171 | the timer function to be used are passed to the constructor. |
| 172 | """ |
| 173 | it = itertools.repeat(None, number) |
| 174 | gcold = gc.isenabled() |
| 175 | gc.disable() |
| 176 | try: |
| 177 | timing = self.inner(it, self.timer) |
| 178 | finally: |
| 179 | if gcold: |
| 180 | gc.enable() |
| 181 | return timing |
| 182 | |
| 183 | def repeat(self, repeat=default_repeat, number=default_number): |
| 184 | """Call timeit() a few times. |