yaspr/ytimers
Example C code evaluating the overhead of commonly used performace timers on x86 and Linux
README
!!! WARNING !!!
Working with timers requires a certain level of focus and attention to detail given that the smallest of changes can trigger catastrophic consequences with regards to the quality of the measurements.
1 - Make sure you RTFM before jumping to conclusions and making dangerous assumptions.
2 - Make sure to identify what you can control and how before doing anything.
# 1 - A code that evaluates the overhead and precision of timers
- RDTSC
- Intel 64 and IA-32 Architectures Software Developer’s Manual chapter 18
(https://xem.github.io/minix86/manual/intel-x86-and-64-manual-vol3/o_fe12b1e2a880e0ce-637.html)
- clock_gettime
- Q: Why only CLOCK_MONOTONIC_RAW matters for performance measurements?
- A: RTFM --> man clock_gettime
CLOCK_MONOTONIC
A nonsettable system-wide clock that represents monotonic time since—as described by POSIX—"some unspecified point in the past". On Linux, that point
corresponds to the number of seconds that the system has been running since it was booted.
The CLOCK_MONOTONIC clock is not affected by discontinuous jumps in the system time (e.g., if the system administrator manually changes the clock),
but is affected by frequency adjustments. This clock does not count time that the system is suspended. All CLOCK_MONOTONIC variants guarantee that
the time returned by consecutive calls will not go backwards, but successive calls may—depending on the architecture—return identical (not-increased)
time values.
CLOCK_MONOTONIC_COARSE (since Linux 2.6.32; Linux-specific)
A faster but less precise version of CLOCK_MONOTONIC. Use when you need very fast, but not fine-grained timestamps. Requires per-architecture sup‐
port, and probably also architecture support for this flag in the vdso(7).
CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific)
Similar to CLOCK_MONOTONIC, but provides access to a raw hardware-based time that is not subject to frequency adjustments. This clock does not count
time that the system is suspended.