1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """Contains the Timer class."""
19
20 import sys
21 import time
22
23
24 -class Timer(object):
25 """
26 A general timer that can measure the elapsed time between
27 a start and end time.
28
29 The timer function used, depends on os (as in timeit.py Python standard library)
30
31 * On Windows, the best timer is time.clock()
32 * On most other platforms the best timer is time.time()
33 """
35 if timer is not None:
36 self.default_timer = timer
37 else:
38 if sys.platform == "win32":
39 self.default_timer = time.clock
40 else:
41 self.default_timer = time.time
42
44 """Start the timer."""
45 self._start = self.default_timer()
46
48 """Stop the timer."""
49 self._end = self.default_timer()
50
51 @property
53 """Return the elapsed time in milliseconds between start and end."""
54 return (self._end - self._start) * 1000
55