wxTimer accuracy experiment (and possible answers to questions!).

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
koekhaos
Earned a small fee
Earned a small fee
Posts: 17
Joined: Tue Jun 13, 2017 7:55 pm

wxTimer accuracy experiment (and possible answers to questions!).

Post by koekhaos » Wed Oct 25, 2017 3:56 am

So I was planning on using wxTimer events in my app I am working on and saw that they are listed as being accurate to within 10ms to 1000ms which seemed like a rather large range! Searching around found a few posts about it but nothing that goes into what actually happens so I decided to do an experiment and this post is to share the results in case it helps anyone or answers a small curiosity!

I basically made a little app that would run 100 wxTimer events on each timer from 0ms to 100ms set on the timers. It would then list the average, minimum, and maximum ms that the event actually fired on. So basically timer->Start(0) run 100x, then timer->Start(1) run 100x, and so on. I ran this on Windows 8.1 Pro 64bit as well as macOS Sierra 10.12 and ubuntu 17.04 64 bit both running on VirtualBox 5.1.28. The results were quite interesting! Windows runs on about 15ms interval ticks so you can see how it steps up based on this. There are in between spots, like at 16ms, where I assume it lands on just before or just after the second tick event leading to about what averages to a half step instead of full step since sometimes it reads 15ms sometimes 30ms. This keeps going predictably. Linux works much better with it even managing to do less than 1ms events! Linux never went below the requested time and on average never went above 1ms. It was definitely the most accurate as far as range. Mac also stayed pretty accurate though it had highs and lows so was a worse range than Linux even if on average is stayed on point best of all three. One interesting thing was that Mac crashed the app if you put 0 into the timer! I'm somewhat curious why Windows chose to go with this sort of event system instead of closer to real time like Linux and Mac.

Time is the setting I put into the timer in ms. Ave is the average ms between event fires of 100 timer events. Min is the minimum in ms between event fires and max is the maximum in ms between event fires. Anyhow, enjoy a buncha numbers!

Code: Select all

-=Windows=-                             -=Linux=-                              -=Mac=-
Time: 0   Ave: 15.6  Min: 8   Max: 22 | Time: 0   Ave: 0.0   Min: 0   Max: 0  | Time: 0   Ave: X     Min: X   Max: X
Time: 1   Ave: 15.6  Min: 6   Max: 22 | Time: 1   Ave: 1.7   Min: 1   Max: 5  | Time: 1   Ave: 1.4   Min: 1   Max: 5
Time: 2   Ave: 15.6  Min: 5   Max: 22 | Time: 2   Ave: 2.8   Min: 2   Max: 10 | Time: 2   Ave: 2.1   Min: 0   Max: 10
Time: 3   Ave: 15.7  Min: 6   Max: 22 | Time: 3   Ave: 4.0   Min: 3   Max: 11 | Time: 3   Ave: 3.2   Min: 1   Max: 10
Time: 4   Ave: 15.6  Min: 10  Max: 22 | Time: 4   Ave: 4.9   Min: 4   Max: 9  | Time: 4   Ave: 4.2   Min: 2   Max: 16
Time: 5   Ave: 15.7  Min: 7   Max: 22 | Time: 5   Ave: 5.8   Min: 5   Max: 10 | Time: 5   Ave: 5.1   Min: 3   Max: 11
Time: 6   Ave: 15.6  Min: 8   Max: 22 | Time: 6   Ave: 6.8   Min: 6   Max: 12 | Time: 6   Ave: 6.2   Min: 4   Max: 13
Time: 7   Ave: 15.6  Min: 8   Max: 22 | Time: 7   Ave: 8.0   Min: 7   Max: 21 | Time: 7   Ave: 7.1   Min: 5   Max: 14
Time: 8   Ave: 15.7  Min: 5   Max: 22 | Time: 8   Ave: 8.8   Min: 8   Max: 11 | Time: 8   Ave: 8.1   Min: 6   Max: 17
Time: 9   Ave: 15.7  Min: 10  Max: 26 | Time: 9   Ave: 9.9   Min: 9   Max: 21 | Time: 9   Ave: 9.1   Min: 6   Max: 18
Time: 10  Ave: 15.6  Min: 8   Max: 23 | Time: 10  Ave: 10.7  Min: 10  Max: 13 | Time: 10  Ave: 10.2  Min: 4   Max: 26
Time: 11  Ave: 15.8  Min: 7   Max: 30 | Time: 11  Ave: 11.8  Min: 11  Max: 26 | Time: 11  Ave: 11.4  Min: 9   Max: 27
Time: 12  Ave: 15.6  Min: 7   Max: 23 | Time: 12  Ave: 12.7  Min: 12  Max: 16 | Time: 12  Ave: 12.2  Min: 3   Max: 33
Time: 13  Ave: 15.7  Min: 8   Max: 28 | Time: 13  Ave: 13.8  Min: 13  Max: 17 | Time: 13  Ave: 13.2  Min: 7   Max: 32
Time: 14  Ave: 15.7  Min: 5   Max: 22 | Time: 14  Ave: 14.7  Min: 14  Max: 18 | Time: 14  Ave: 14.1  Min: 11  Max: 20
Time: 15  Ave: 16.1  Min: 8   Max: 60 | Time: 15  Ave: 15.8  Min: 15  Max: 18 | Time: 15  Ave: 15.5  Min: 2   Max: 41
Time: 16  Ave: 25.0  Min: 14  Max: 38 | Time: 16  Ave: 18.5  Min: 16  Max: 62 | Time: 16  Ave: 16.2  Min: 6   Max: 39
Time: 17  Ave: 31.2  Min: 29  Max: 34 | Time: 17  Ave: 17.7  Min: 15  Max: 22 | Time: 17  Ave: 17.1  Min: 15  Max: 25
Time: 18  Ave: 31.4  Min: 28  Max: 46 | Time: 18  Ave: 18.7  Min: 18  Max: 22 | Time: 18  Ave: 18.1  Min: 7   Max: 35
Time: 19  Ave: 31.3  Min: 26  Max: 35 | Time: 19  Ave: 19.8  Min: 19  Max: 32 | Time: 19  Ave: 19.1  Min: 5   Max: 33
Time: 20  Ave: 33.3  Min: 12  Max: 145| Time: 20  Ave: 20.8  Min: 20  Max: 32 | Time: 20  Ave: 20.1  Min: 8   Max: 30
Time: 21  Ave: 31.9  Min: 19  Max: 76 | Time: 21  Ave: 22.3  Min: 21  Max: 44 | Time: 21  Ave: 21.3  Min: 15  Max: 48
Time: 22  Ave: 31.6  Min: 25  Max: 63 | Time: 22  Ave: 25.7  Min: 22  Max: 63 | Time: 22  Ave: 22.1  Min: 9   Max: 33
Time: 23  Ave: 31.5  Min: 24  Max: 59 | Time: 23  Ave: 24.6  Min: 23  Max: 58 | Time: 23  Ave: 23.3  Min: 20  Max: 46
Time: 24  Ave: 31.4  Min: 25  Max: 47 | Time: 24  Ave: 24.7  Min: 24  Max: 35 | Time: 24  Ave: 24.1  Min: 14  Max: 36
Time: 25  Ave: 31.4  Min: 23  Max: 46 | Time: 25  Ave: 25.7  Min: 25  Max: 34 | Time: 25  Ave: 25.1  Min: 20  Max: 37
Time: 26  Ave: 31.6  Min: 23  Max: 68 | Time: 26  Ave: 26.7  Min: 26  Max: 32 | Time: 26  Ave: 26.4  Min: 4   Max: 50
Time: 27  Ave: 31.5  Min: 22  Max: 58 | Time: 27  Ave: 27.9  Min: 27  Max: 55 | Time: 27  Ave: 27.5  Min: 17  Max: 54
Time: 28  Ave: 31.8  Min: 21  Max: 80 | Time: 28  Ave: 28.9  Min: 28  Max: 63 | Time: 28  Ave: 28.2  Min: 16  Max: 45
Time: 29  Ave: 31.4  Min: 23  Max: 46 | Time: 29  Ave: 29.6  Min: 29  Max: 34 | Time: 29  Ave: 29.8  Min: 1   Max: 69
Time: 30  Ave: 31.5  Min: 24  Max: 63 | Time: 30  Ave: 30.6  Min: 30  Max: 41 | Time: 30  Ave: 30.2  Min: 23  Max: 49
Time: 31  Ave: 31.8  Min: 24  Max: 78 | Time: 31  Ave: 31.6  Min: 31  Max: 42 | Time: 31  Ave: 31.2  Min: 25  Max: 49
Time: 32  Ave: 42.1  Min: 30  Max: 88 | Time: 32  Ave: 32.7  Min: 32  Max: 43 | Time: 32  Ave: 32.1  Min: 27  Max: 43
Time: 33  Ave: 47.2  Min: 44  Max: 78 | Time: 33  Ave: 33.6  Min: 33  Max: 43 | Time: 33  Ave: 33.2  Min: 28  Max: 48
Time: 34  Ave: 47.2  Min: 43  Max: 80 | Time: 34  Ave: 34.6  Min: 34  Max: 45 | Time: 34  Ave: 34.2  Min: 20  Max: 52
Time: 35  Ave: 47.3  Min: 42  Max: 93 | Time: 35  Ave: 35.5  Min: 35  Max: 45 | Time: 35  Ave: 35.2  Min: 25  Max: 54
Time: 36  Ave: 47.2  Min: 43  Max: 80 | Time: 36  Ave: 36.5  Min: 36  Max: 41 | Time: 36  Ave: 36.2  Min: 13  Max: 60
Time: 37  Ave: 47.2  Min: 44  Max: 77 | Time: 37  Ave: 37.7  Min: 37  Max: 47 | Time: 37  Ave: 37.1  Min: 24  Max: 50
Time: 38  Ave: 47.2  Min: 41  Max: 83 | Time: 38  Ave: 38.6  Min: 38  Max: 50 | Time: 38  Ave: 38.1  Min: 35  Max: 50
Time: 39  Ave: 47.2  Min: 42  Max: 82 | Time: 39  Ave: 39.6  Min: 39  Max: 42 | Time: 39  Ave: 39.2  Min: 19  Max: 59
Time: 40  Ave: 47.2  Min: 44  Max: 74 | Time: 40  Ave: 40.6  Min: 40  Max: 49 | Time: 40  Ave: 40.2  Min: 36  Max: 52
Time: 41  Ave: 47.3  Min: 44  Max: 94 | Time: 41  Ave: 41.6  Min: 41  Max: 46 | Time: 41  Ave: 41.2  Min: 34  Max: 61
Time: 42  Ave: 47.3  Min: 44  Max: 94 | Time: 42  Ave: 42.7  Min: 42  Max: 53 | Time: 42  Ave: 42.1  Min: 32  Max: 60
Time: 43  Ave: 47.3  Min: 44  Max: 95 | Time: 43  Ave: 43.6  Min: 43  Max: 54 | Time: 43  Ave: 43.2  Min: 34  Max: 64
Time: 44  Ave: 47.4  Min: 44  Max: 95 | Time: 44  Ave: 44.7  Min: 44  Max: 55 | Time: 44  Ave: 44.4  Min: 30  Max: 79
Time: 45  Ave: 47.3  Min: 44  Max: 91 | Time: 45  Ave: 45.7  Min: 45  Max: 57 | Time: 45  Ave: 45.2  Min: 37  Max: 65
Time: 46  Ave: 47.3  Min: 44  Max: 93 | Time: 46  Ave: 46.7  Min: 46  Max: 59 | Time: 46  Ave: 46.2  Min: 33  Max: 64
Time: 47  Ave: 50.4  Min: 40  Max: 93 | Time: 47  Ave: 47.7  Min: 47  Max: 58 | Time: 47  Ave: 47.1  Min: 38  Max: 57
Time: 48  Ave: 63.1  Min: 59  Max: 118| Time: 48  Ave: 48.7  Min: 48  Max: 58 | Time: 48  Ave: 48.2  Min: 38  Max: 70
Time: 49  Ave: 63.0  Min: 60  Max: 110| Time: 49  Ave: 49.8  Min: 49  Max: 60 | Time: 49  Ave: 49.3  Min: 42  Max: 70
Time: 50  Ave: 63.0  Min: 59  Max: 109| Time: 50  Ave: 50.8  Min: 50  Max: 61 | Time: 50  Ave: 50.2  Min: 27  Max: 72
Time: 51  Ave: 62.8  Min: 58  Max: 92 | Time: 51  Ave: 51.7  Min: 51  Max: 62 | Time: 51  Ave: 51.1  Min: 35  Max: 66
Time: 52  Ave: 62.8  Min: 58  Max: 94 | Time: 52  Ave: 52.6  Min: 52  Max: 57 | Time: 52  Ave: 52.1  Min: 44  Max: 63
Time: 53  Ave: 63.0  Min: 55  Max: 108| Time: 53  Ave: 53.7  Min: 53  Max: 64 | Time: 53  Ave: 53.2  Min: 44  Max: 76
Time: 54  Ave: 63.0  Min: 55  Max: 109| Time: 54  Ave: 54.6  Min: 54  Max: 57 | Time: 54  Ave: 54.2  Min: 42  Max: 73
Time: 55  Ave: 62.6  Min: 55  Max: 75 | Time: 55  Ave: 55.7  Min: 55  Max: 62 | Time: 55  Ave: 55.2  Min: 49  Max: 72
Time: 56  Ave: 62.8  Min: 55  Max: 92 | Time: 56  Ave: 56.7  Min: 56  Max: 61 | Time: 56  Ave: 56.2  Min: 52  Max: 76
Time: 57  Ave: 63.5  Min: 36  Max: 150| Time: 57  Ave: 57.7  Min: 57  Max: 64 | Time: 57  Ave: 57.2  Min: 48  Max: 77
Time: 58  Ave: 63.0  Min: 56  Max: 104| Time: 58  Ave: 58.8  Min: 58  Max: 68 | Time: 58  Ave: 58.1  Min: 56  Max: 65
Time: 59  Ave: 62.9  Min: 55  Max: 104| Time: 59  Ave: 59.7  Min: 59  Max: 66 | Time: 59  Ave: 59.3  Min: 56  Max: 81
Time: 60  Ave: 63.0  Min: 52  Max: 115| Time: 60  Ave: 60.8  Min: 60  Max: 70 | Time: 60  Ave: 60.1  Min: 44  Max: 75
Time: 61  Ave: 62.8  Min: 53  Max: 88 | Time: 61  Ave: 61.7  Min: 61  Max: 72 | Time: 61  Ave: 61.2  Min: 41  Max: 86
Time: 62  Ave: 62.8  Min: 54  Max: 94 | Time: 62  Ave: 62.8  Min: 62  Max: 71 | Time: 62  Ave: 62.2  Min: 51  Max: 86
Time: 63  Ave: 75.4  Min: 61  Max: 120| Time: 63  Ave: 63.7  Min: 63  Max: 70 | Time: 63  Ave: 63.2  Min: 52  Max: 86
Time: 64  Ave: 78.4  Min: 76  Max: 109| Time: 64  Ave: 64.8  Min: 64  Max: 76 | Time: 64  Ave: 64.2  Min: 53  Max: 85
Time: 65  Ave: 78.4  Min: 75  Max: 110| Time: 65  Ave: 65.7  Min: 65  Max: 69 | Time: 65  Ave: 65.2  Min: 63  Max: 86
Time: 66  Ave: 78.3  Min: 74  Max: 95 | Time: 66  Ave: 66.7  Min: 66  Max: 71 | Time: 66  Ave: 66.2  Min: 56  Max: 84
Time: 67  Ave: 78.5  Min: 74  Max: 113| Time: 67  Ave: 67.7  Min: 67  Max: 71 | Time: 67  Ave: 67.1  Min: 60  Max: 79
Time: 68  Ave: 78.6  Min: 72  Max: 123| Time: 68  Ave: 68.7  Min: 68  Max: 74 | Time: 68  Ave: 68.1  Min: 58  Max: 82
Time: 69  Ave: 78.5  Min: 71  Max: 108| Time: 69  Ave: 69.8  Min: 69  Max: 80 | Time: 69  Ave: 69.1  Min: 62  Max: 81
Time: 70  Ave: 78.6  Min: 70  Max: 119| Time: 70  Ave: 70.8  Min: 70  Max: 84 | Time: 70  Ave: 70.2  Min: 66  Max: 93
Time: 71  Ave: 78.7  Min: 71  Max: 126| Time: 71  Ave: 71.7  Min: 71  Max: 81 | Time: 71  Ave: 71.2  Min: 60  Max: 87
Time: 72  Ave: 78.6  Min: 69  Max: 119| Time: 72  Ave: 72.7  Min: 72  Max: 80 | Time: 72  Ave: 72.2  Min: 50  Max: 98
Time: 73  Ave: 78.4  Min: 70  Max: 103| Time: 73  Ave: 73.7  Min: 73  Max: 83 | Time: 73  Ave: 73.2  Min: 66  Max: 90
Time: 74  Ave: 78.3  Min: 70  Max: 93 | Time: 74  Ave: 74.8  Min: 74  Max: 85 | Time: 74  Ave: 74.2  Min: 65  Max: 91
Time: 75  Ave: 78.4  Min: 71  Max: 106| Time: 75  Ave: 75.8  Min: 75  Max: 88 | Time: 75  Ave: 75.2  Min: 66  Max: 88
Time: 76  Ave: 78.5  Min: 70  Max: 114| Time: 76  Ave: 76.8  Min: 76  Max: 88 | Time: 76  Ave: 76.2  Min: 56  Max: 96
Time: 77  Ave: 78.4  Min: 68  Max: 105| Time: 77  Ave: 77.7  Min: 77  Max: 85 | Time: 77  Ave: 77.1  Min: 71  Max: 85
Time: 78  Ave: 78.6  Min: 68  Max: 131| Time: 78  Ave: 78.7  Min: 78  Max: 90 | Time: 78  Ave: 78.2  Min: 67  Max: 102
Time: 79  Ave: 94.0  Min: 77  Max: 137| Time: 79  Ave: 79.7  Min: 79  Max: 83 | Time: 79  Ave: 79.1  Min: 70  Max: 89
Time: 80  Ave: 94.2  Min: 91  Max: 142| Time: 80  Ave: 80.7  Min: 80  Max: 91 | Time: 80  Ave: 80.2  Min: 71  Max: 104
Time: 81  Ave: 94.2  Min: 91  Max: 142| Time: 81  Ave: 81.7  Min: 81  Max: 91 | Time: 81  Ave: 81.2  Min: 66  Max: 101
Time: 82  Ave: 94.2  Min: 91  Max: 143| Time: 82  Ave: 82.8  Min: 82  Max: 93 | Time: 82  Ave: 82.1  Min: 73  Max: 91
Time: 83  Ave: 93.9  Min: 90  Max: 111| Time: 83  Ave: 83.8  Min: 83  Max: 98 | Time: 83  Ave: 83.2  Min: 76  Max: 106
Time: 84  Ave: 94.0  Min: 91  Max: 123| Time: 84  Ave: 84.7  Min: 84  Max: 93 | Time: 84  Ave: 84.2  Min: 66  Max: 110
Time: 85  Ave: 94.2  Min: 91  Max: 142| Time: 85  Ave: 85.7  Min: 85  Max: 95 | Time: 85  Ave: 85.2  Min: 79  Max: 100
Time: 86  Ave: 94.2  Min: 91  Max: 142| Time: 86  Ave: 86.7  Min: 86  Max: 96 | Time: 86  Ave: 86.3  Min: 80  Max: 113
Time: 87  Ave: 94.2  Min: 91  Max: 142| Time: 87  Ave: 87.7  Min: 87  Max: 98 | Time: 87  Ave: 87.2  Min: 82  Max: 102
Time: 88  Ave: 93.9  Min: 87  Max: 114| Time: 88  Ave: 88.8  Min: 88  Max: 97 | Time: 88  Ave: 88.3  Min: 84  Max: 116
Time: 89  Ave: 93.9  Min: 87  Max: 106| Time: 89  Ave: 89.8  Min: 89  Max: 97 | Time: 89  Ave: 89.2  Min: 81  Max: 113
Time: 90  Ave: 93.9  Min: 91  Max: 108| Time: 90  Ave: 90.7  Min: 90  Max: 100| Time: 90  Ave: 90.3  Min: 79  Max: 116
Time: 91  Ave: 94.0  Min: 86  Max: 115| Time: 91  Ave: 91.7  Min: 91  Max: 104| Time: 91  Ave: 91.2  Min: 83  Max: 110
Time: 92  Ave: 93.9  Min: 87  Max: 103| Time: 92  Ave: 92.7  Min: 92  Max: 102| Time: 92  Ave: 92.3  Min: 83  Max: 118
Time: 93  Ave: 93.9  Min: 91  Max: 107| Time: 93  Ave: 93.8  Min: 93  Max: 104| Time: 93  Ave: 93.1  Min: 78  Max: 109
Time: 94  Ave: 100.2 Min: 92  Max: 124| Time: 94  Ave: 94.8  Min: 94  Max: 97 | Time: 94  Ave: 94.3  Min: 88  Max: 126
Time: 95  Ave: 109.5 Min: 107 Max: 125| Time: 95  Ave: 95.8  Min: 95  Max: 98 | Time: 95  Ave: 95.1  Min: 92  Max: 105
Time: 96  Ave: 109.5 Min: 106 Max: 127| Time: 96  Ave: 96.8  Min: 96  Max: 100| Time: 96  Ave: 96.1  Min: 92  Max: 105
Time: 97  Ave: 109.6 Min: 105 Max: 124| Time: 97  Ave: 97.8  Min: 97  Max: 100| Time: 97  Ave: 97.1  Min: 95  Max: 107
Time: 98  Ave: 109.5 Min: 105 Max: 123| Time: 98  Ave: 98.8  Min: 98  Max: 101| Time: 98  Ave: 98.1  Min: 93  Max: 107
Time: 99  Ave: 109.5 Min: 104 Max: 123| Time: 99  Ave: 99.7  Min: 99  Max: 102| Time: 99  Ave: 99.1  Min: 96  Max: 107
Time: 100 Ave: 109.5 Min: 103 Max: 128| Time: 100 Ave: 100.8 Min: 100 Max: 110| Time: 100 Ave: 100.1 Min: 96  Max: 108

User avatar
doublemax
Moderator
Moderator
Posts: 14895
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTimer accuracy experiment (and possible answers to questions!).

Post by doublemax » Wed Oct 25, 2017 5:40 am

viewtopic.php?p=166190#p166190
viewtopic.php?f=1&t=42313

If you find some easy-to-use high-resolution timer code for Windows, i'd be interested, too :)
Use the source, Luke!

koekhaos
Earned a small fee
Earned a small fee
Posts: 17
Joined: Tue Jun 13, 2017 7:55 pm

Re: wxTimer accuracy experiment (and possible answers to questions!).

Post by koekhaos » Wed Oct 25, 2017 6:43 am

To be honest at this point I'm not really considering beyond this since the app I am planning doesn't need to be to the millisecond. It was mostly an exercise to see exactly what the actual response is since I was worried about that 1 full second mention! Even with it's being 15ms or so off in Windows you still get over 60 updates a second which is plenty good enough for most cases I would need. Any app I can think of that I would make that would need better than that would be a game and I wouldn't use wxWidgets for that but SFML, SDL, or Unity or something of the like which you program directly off the main loop which runs as fast as it possibly can. :) If I do ever run across something interesting I will let you know though. Now that I think about it though, would just running a loop in a second thread constantly comparing current time to last time not be able to easily pass events at a higher resolution or would it still not receive them any quicker? I've never used a separate thread before but if I understand them correctly they are running parallel and so shouldn't interfere with the main thread right? Edit: I just noticed that one of your links I think is talking about this exact thing being not so good on the cpu so never mind!

In any case, I think Linux is the winner for server software. It was by far the easiest to set up environment and get going. Literally like 15 minutes from download to compile whereas I spent hours figuring out how to get Windows and Mac to compile/link properly! Add in it's superior capability with this event timer and awesome stability it almost boggles my mind people still use Windows! Hell, they even proved that games can run faster on Linux than Windows!

Post Reply