An addictively fast time measurement library designed for counting nanoseconds.
It's so fast, it might even be able to measure your attention span! 🔥💀 - Anonymous
#include <stdio.h>
#include "tocktick.h"
int main() {
// calibrate the timer
tock(tick());
uint64_t start = tick();
printf("Hello, world!\n");
uint64_t elapsed_ns = tock(start);
printf("Printing took %lu ns\n", elapsed_ns);
return 0;
}
Output:
./build/test/test_print
Hello, world!
Printing took 4654 ns (must not be on Windows!)
The typical time measurement error is on the order of 0.01%, or 1/10000 with the default calibration settings used when you initialize with tock(tick())
and measure durations below one second.
For very-accurate time counting, make sure you explicitly calibrate with a large duration. This will cause your program to sleep for an extended period during calibration.
tockcalibrate(1000000000);
This is a library for counting nanoseconds, not seconds, minutes, hours, or days.
This package relies on a static variable for calibration, so you may get incorrect results in multi-threaded environments or if your program moves between processors on certain architectures.
The delta of counter values is converted to a floating point for performance reasons when doing elapsed time calculations, so be aware of this when attempting to measure large durations.
⚖️ The Unlicense ⚖️
This was written for Roadrunner Dynamics