Skip to content

Commit aa007a2

Browse files
committed
Update accuracy tests and graphs
1 parent 4ca3c1e commit aa007a2

13 files changed

+97
-32
lines changed

AccuracyTests.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
# Accuracy test
3+
4+
This file summarizes accuracy test for loops of constant duration using the `oclock.Timer` class. Tests are done using the performance_test function (see *Readme.md*), e.g.
5+
```python
6+
from oclock.performance import performance_test
7+
performance_test(dt=0.1, nloops=1000, fmax=0.5, plot=True, precise=True)
8+
```
9+
10+
Below are some results on timing accuracy in an Unix Environment (MacOS) and Windows, using `nloops=1000`, `fmax=0.5` for various values of `dt`. *Regular Timer* means with `precise=False` while *Precise Timer* means with `precise=True`.
11+
12+
## Unix
13+
14+
### Regular Timer
15+
16+
| Requested `dt` (ms) | 1000 | 100 | 40 | 10 | 1 |
17+
|:----------------------------------:|:------:|:-------:|:-------:|:-------:|:-------:|
18+
| average `dt` - requested `dt` (ms) | 0.0012 | 0.00012 | 0.00016 | 0.00005 | 0.00023 |
19+
| standard deviation in `dt` (ms) | 0.48 | 0.36 | 0.31 | 0.23 | 0.08 |
20+
21+
Corresponding graphs:
22+
23+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/timer_macos_1000ms.png)
24+
25+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/timer_macos_100ms.png)
26+
27+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/timer_macos_400ms.png)
28+
29+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/timer_macos_10ms.png)
30+
31+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/timer_macos_1ms.png)
32+
33+
34+
### Precise Timer
35+
36+
| Requested `dt` (ms) | 1000 | 100 | 40 | 10 | 1 |
37+
|:----------------------------------:|:------:|:-------:|:-------:|:-------:|:-------:|
38+
| average `dt` - requested `dt` (ms) | 3.6E-5 | 3.4E-5 | 2.8E-5 | 3.0E-5 | 1.2E-5 |
39+
| standard deviation in `dt` (ms) | 0.0118 | 0.0104 | 0.0117 | 0.0105 | 0.0073 |
40+
41+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/precisetimer_macos_1000ms.png)
42+
43+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/precisetimer_macos_100ms.png)
44+
45+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/precisetimer_macos_400ms.png)
46+
47+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/precisetimer_macos_10ms.png)
48+
49+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/precisetimer_macos_1ms.png)
50+
51+
52+
## Windows
53+
54+
### Regular Timer
55+
56+
| Requested `dt` (ms) | 1000 | 100 | 40 | 10 | 1 |
57+
|:----------------------------------:|:-----:|:-------:|:-------:|:-------:|:---:|
58+
| average `dt` - requested `dt` (ms) | 0.014 | 0.0015 | 0.0013 | 1.2 | 1.1 |
59+
| standard deviation in `dt` (ms) | 7.0 | 7.1 | 7.0 | 5.6 | 1.9 |
60+
61+
62+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/timer_windows_1000ms.png)
63+
64+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/timer_windows_100ms.png)
65+
66+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/timer_windows_400ms.png)
67+
68+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/timer_windows_10ms.png)
69+
70+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/timer_windows_1ms.png)
71+
72+
73+
### Precise Timer
74+
75+
76+
| Requested `dt` (ms) | 1000 | 100 | 40 | 10 | 1 |
77+
|:----------------------------------:|:------:|:-------:|:-------:|:-------:|:-------:|
78+
| average `dt` - requested `dt` (ms) | 1.3E-5 | 1.5E-5 | 1.6E-5 | 6.7E-6 | 1.5E-6 |
79+
| standard deviation in `dt` (ms) | 0.0066 | 0.0100 | 0.0088 | 0.0068 | 0.0036 |
80+
81+
82+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/precisetimer_windows_1000ms.png)
83+
84+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/precisetimer_windows_100ms.png)
85+
86+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/precisetimer_windows_400ms.png)
87+
88+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/precisetimer_windows_10ms.png)
89+
90+
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/precisetimer_windows_1ms.png)

README.md

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -270,46 +270,21 @@ timer.interval_exceeded # (bool) True if loop contents take longer to execut
270270
- After calling `pause()`, the `checkpt()` command blocks until `resume()` is called, however in the current version after `stop()` the `checkpt()` becomes non-blocking (equivalent to a `pass`), so that all following lines will be executed immediately and without any waiting time (i.e. as fast as possible if within a loop), until `timer.reset()` is called again. This means that it is useful to pin the condition of the loop to the stopping of the timer (see examples).
271271

272272

273-
## Accuracy test
273+
## Timer accuracy
274274

275-
See *performance.py* file of the module for functions to test the accuracy of the timer. In particular:
275+
See *performance.py* file of the module for functions to test the behavior and accuracy of the timer. In particular:
276276
```python
277277
from oclock.performance import performance_test
278-
performance_test(dt=0.1, nloops=1000, fmax=0.99)
278+
performance_test(dt=0.01, nloops=1000, fmax=0.99, plot=True, warnings=False, precise=True)
279279
```
280-
tests the timing on 1000 loops of requested duration 0.1 second (100ms), using within the loop a function sleeping for a random amount of time between 0 and 0.99*dt (use `plot=True` option to see the results on a *matplotlib* graph, and `warnings=True` to have a printed warning when the execution time of the nested commands exceed the target duration of the loop).
280+
tests the timing on 1000 loops of requested duration 0.01 second (10ms), using within the loop a function sleeping for a random amount of time between 0 and 0.99 dt (with `plot=True` option to see the results on a *matplotlib* graph, and `warnings=False` to not have a printed warning when the execution time of the nested commands exceed the target duration of the loop); `precise=True` uses the timer in precise mode.
281281

282-
Below are some quick preliminary results on timing accuracy in an Unix Environment (MacOS) and Windows, using `nloops=1000`, `fmax=0.5` for various values of `dt`. As can be seen, The Timer seems to perform well in Unix environments even down to millisecond intervals (1000fps), while it starts having difficulties below 40 ms intervals in Windows (25 fps).
282+
The *AccuracyTests.md* file gathers some accuracy results in Unix and Windows environments. In summary:
283283

284-
### Unix (MacOS)
284+
- with **Unix**, time fluctuations are < 0.5 ms with the regular timer, and on the order of 0.01 ms (standard deviation) with the precise timer
285285

286-
| Requested `dt` (ms) | 1000 | 100 (*) | 40 | 10 (**) | 1 |
287-
|:----------------------------------:|:------:|:-------:|:-------:|:-------:|:-------:|
288-
| average `dt` - requested `dt` (ms) | 0.0012 | 0.00012 | 0.00016 | 0.00005 | 0.00023 |
289-
| standard deviation in `dt` (ms) | 0.48 | 0.36 | 0.31 | 0.23 | 0.08 |
286+
- with **Windows**, the regular timer fails quickly as frame rate is increased, due to fluctuations in the ~ 10 ms range. However the precise timer performs even better than in Unix, with fluctuations of less than 0.01 ms (standard deviation).
290287

291-
(*) corresponding graph:
292-
293-
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/timer_macos_100ms.png)
294-
295-
(**) corresponding graph:
296-
297-
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/timer_macos_10ms.png)
298-
299-
300-
### Windows
301-
302-
| Requested `dt` (ms) | 1000 | 100 (*) | 40 | 10 (**) | 1 |
303-
|:----------------------------------:|:-----:|:-------:|:-------:|:-------:|:---:|
304-
| average `dt` - requested `dt` (ms) | 0.014 | 0.0015 | 0.0013 | 1.2 | 1.1 |
305-
| standard deviation in `dt` (ms) | 7.0 | 7.1 | 7.0 | 5.6 | 1.9 |
306-
307-
308-
(*) corresponding graph:
309-
310-
![](https://raw.githubusercontent.com/ovinc/oclock/master/media/img/timer_windows_100ms.png)
311-
312-
(**) Due to the large time fluctuations in Windows at this timescale, the use of the Timer is not really relevant anymore at theses interval values and lower. Work is under way to improve accuracy.
313288

314289
## Behavior when interval is exceeded
315290

34 KB
Loading
33.3 KB
Loading
34.6 KB
Loading
37.9 KB
Loading
35.4 KB
Loading
23.2 KB
Loading
29.5 KB
Loading
30.1 KB
Loading

0 commit comments

Comments
 (0)