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