Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #6668
| From | "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> |
|---|---|
| Newsgroups | comp.programming |
| Subject | Re: Time measuring on Windows |
| Date | 2016-05-29 17:16 +0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <nif14l$19hb$1@gioia.aioe.org> (permalink) |
| References | <niee0v$ded$1@dont-email.me> |
On 2016-05-29 11:53, BartC wrote: > I need to measure how long short processes take to execute. > > All the docs point to using QueryPerformanceCounter() (as opposed to > using, for example, the RDTSC machine instruction). > > But I'm getting crazy results. > > If I call QPC(), then count to ten million (a task that should take 8ms > based on how long it took to count to a billion), and call it again, the > difference between the two readings should give an indication of how > long it took. > > But I've seen results from 180,000 to over 600,000! (Even RDTSC gives me > 20M to 42M, but that's across two cores; I thought QPC was supposed to > fix that). I understand values need to be scaled to get actual times, > but the problem is they are inconsistent. They are consistent, we are using performance counter for fine time measurements. The time in seconds is obtained with QueryPerformanceFrequency. Ticks do not make sense. 8ms is too short for statistically correct measurements, e.g. when your thread loses processor it will not return until next 10ms on a busy machine. > Is there a more reliable way of measuring execution times in the > millisecond range? The method is very reliable though time measurement are tricky, especially in presence of time sharing. Under Windows, depending on settings, switching threads that do not enter non-busy waiting takes 10ms to 1ms (which is the minimum), controlled by timer resolution. In order to ensure 1ms timer resolution call timeBeginPeriod (1) and see if the spread decreases. You can also set the thread priority to above-normal or even real-time. > (This is for a process within a program; I don't want to use an external > utility to measure the complete runtime of an executable as that will > include all sorts of overheads.) Well, you cannot measure thread CPU time under Windows, if that is what you mean. Performance counter is for very accurate and fine real-time measurements. Thread's CPU and kernel times can be queried but the result has a systematic error in it. Theoretically you can have 100% load with 0% CPU time indicated. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Time measuring on Windows BartC <bc@freeuk.com> - 2016-05-29 10:53 +0100
Re: Time measuring on Windows "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2016-05-29 17:16 +0200
Re: Time measuring on Windows BartC <bc@freeuk.com> - 2016-05-29 17:32 +0100
Re: Time measuring on Windows "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2016-05-29 19:04 +0200
csiph-web