Benchmark   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 20
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 4 1
1
import time
2
import sys
3
4
if sys.platform == "win32":
5
    default_timer = time.clock
6
else:
7
    default_timer = time.time
8
9
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