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)
| 171 | traceback.print_exc(file=file, **kwargs) |
| 172 | |
| 173 | def timeit(self, number=default_number): |
| 174 | """Time 'number' executions of the main statement. |
| 175 | |
| 176 | To be precise, this executes the setup statement once, and |
| 177 | then returns the time it takes to execute the main statement |
| 178 | a number of times, as float seconds if using the default timer. The |
| 179 | argument is the number of times through the loop, defaulting |
| 180 | to one million. The main statement, the setup statement and |
| 181 | the timer function to be used are passed to the constructor. |
| 182 | """ |
| 183 | it = itertools.repeat(None, number) |
| 184 | gcold = gc.isenabled() |
| 185 | gc.disable() |
| 186 | try: |
| 187 | timing = self.inner(it, self.timer) |
| 188 | finally: |
| 189 | if gcold: |
| 190 | gc.enable() |
| 191 | return timing |
| 192 | |
| 193 | def repeat(self, repeat=default_repeat, number=default_number): |
| 194 | """Call timeit() a few times. |