Alex Rivera | Logout

C++ high precision time measurement in Windows

Asked 2009-12-01T11:58:05.137
33

I'm interested in measuring a specific point in time down to the nanosecond using C++ in Windows. Is this possible? If it isn't, is it possible to get the specific time in microseconds at least?. Any library should do, unless I suppose it's possible with managed code. thanks

Edit
Report

2 Answers

1

You can use the Performance Counter API as Konrad Rudolf proposed, but should be warned that it is based on the CPU frequency. This frequency is not stable when e.g. a power save mode is enabled. If you want to use this API, make sure the CPU is at a constant frequency.

Otherwise, you can create some kind of 'statistical' system, correlating the CPU ticks to the PC BIOS clock. The latter is way less precise, but constant.

answered 2009-12-01T12:06:16.837
0

using QueryPerformanceCounter (for windows)

answered 2009-12-01T12:02:33.963

Your Answer