File size: 481 Bytes
1512437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from timeit import default_timer as timer

class benchmark(object):

    def __init__(self, msg, fmt="%0.9g", times=1):
        self.msg = msg
        self.fmt = fmt
        self.count = 0
        self.end = times
        self.measured = np.zeros(times)

    def __enter__(self):
        self.start = timer()
        return self

    def __exit__(self, *args):
        t = timer() - self.start
        print(("%s : " + self.fmt + " seconds") % (self.msg, t))
        self.time = t