| Total Complexity | 4 |
| Total Lines | 20 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | import time |
||
| 10 | class Benchmark(): |
||
| 11 | |||
| 12 | def __init__(self, func, name, repeat=3): |
||
| 13 | self.func = func |
||
| 14 | self.repeat = repeat |
||
| 15 | self.name = name |
||
| 16 | |||
| 17 | def __str__(self): |
||
| 18 | return "<Benchmark {}>".format(self.name) |
||
| 19 | |||
| 20 | def run(self, transaction): |
||
| 21 | self.results = [] |
||
| 22 | for x in range(self.repeat): |
||
| 23 | start = default_timer() |
||
| 24 | self.func() |
||
| 25 | end = default_timer() |
||
| 26 | elapsed = end - start |
||
| 27 | self.results.append(elapsed) |
||
| 28 | transaction.rollback() |
||
| 29 | return min(self.results) |
||
| 30 |