| 1 | std::chrono::steady_clock | Monotonic tick count (no wall-clock meaning) | 0.1–1 µs on most PCs | • Standard C++ – portable• Monotonic (never goes backward)• Wraparound handled by library | • Uses QueryPerformanceCounter under the hood → inherits its quirks• No absolute “time of day” | auto t = std::chrono::steady_clock::now(); |
| 2 | std::chrono::high_resolution_clock | “Best” clock for the implementation (often == steady_clock on Windows) | Same as 1 | • Same as #1, plus expressive durations | • On MSVC it’s just an alias; on other OSes it can be wall-clock → portability surprise | auto t = std::chrono::high_resolution_clock::now(); |
| 3 | std::chrono::system_clock | Wall-clock (UTC) since 1970-01-01 | ~1 ms | • Portable wall-clock• Converts to time_t easily | • Can jump if user/NTP changes time• Not monotonic ⇒ unsafe for interval timing | auto t = std::chrono::system_clock::now(); |
| 4 | QueryPerformanceCounter / QueryPerformanceFrequency | 64-bit tick count since boot | 0.1–1 µs | • Highest, stable resolution in user mode• Monotonic (post-Win XP SP2)• Immune to DST/NTP/user changes | • Requires 2 calls + math• On some virtual/old HW can drift vs. wall clock | LARGE_INTEGER qpc; QueryPerformanceCounter(&qpc); |
| 5 | GetTickCount (32-bit) | ms since boot | 1 ms (but coarse timer granularity) | • One cheap call• Always available (Win 95+) | • Wraps at 49.7 days → bugs!• Low resolution (depends on timeBeginPeriod) | DWORD ms = GetTickCount(); |
| 6 | GetTickCount64 | 64-bit ms since boot | 1 ms | • Same as #5 but no wrap for ~584 million years | • Still millisecond granularity• Not on pre-Vista | ULONGLONG ms = GetTickCount64(); |
| 7 | timeGetTime (WinMM) | ms since boot | 1 ms (can be 1 ms after timeBeginPeriod(1)) | • Old games & multimedia code rely on it• Not affected by time-of-day changes | • Same wrap as GetTickCount (32-bit)• Calling timeBeginPeriod hurts system-wide power/perf | DWORD ms = timeGetTime(); |
| 8 | GetSystemTimeAsFileTime / GetSystemTimePreciseAsFileTime (≥Win 8) | 100-ns intervals since 1601-01-01 | 1 ms / ≤1 µs (precise ver.) | • Fast 1-call wall clock• Precise ver. good for event timestamps | • Wall clock can jump• FILETIME math is clunky | FILETIME ft; GetSystemTimePreciseAsFileTime(&ft); |
| 9 | CRT clock() | CPU time used by current process | ~1 ms | • ISO C• Useful for quick “how much CPU?” | • Not wall/real time• Poor granularity in multithread apps | clock_t c = clock(); |
| 10 | GetProcessTimes / GetThreadTimes | Kernel/user CPU time | 100 ns | • Distinguish user vs kernel CPU | • Slower (syscall) | FILETIME u,k,cr,ex; GetProcessTimes(...); |
| 11 | __rdtsc intrinsic (RDTSC) | Raw TSC cycles | ~0.3 ns | • Ultra low latency (few cycles)• Good for micro-bench in same core | • Must convert cycles → time (need TSC freq)• Not serializing; clock drift across CPUs; tricky on laptops/C-states | unsigned long long c = __rdtsc(); |
| 12 | NtQuerySystemTime (NTDLL, undocumented) | 100-ns since 1601 | ~1 ms | • One call, no kernel mode switch (fast) | • Not officially documented — risky for production | extern "C" NTSTATUS NtQuerySystemTime(LARGE_INTEGER*); |