~alecgraves/tocktick

An addictive library for measuring your attention span
cd0943d5 — Alec Graves 11 months ago
add windows and build.bat

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~alecgraves/tocktick
read/write
git@git.sr.ht:~alecgraves/tocktick

You can also use your local clone with git send-email.

#tocktick

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

#Example

#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!)

#Timing Accuracy ⏱️

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.

#Developer Notes 📝

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.

#License

⚖️ The Unlicense ⚖️

This was written for Roadrunner Dynamics

Do not follow this link