Skip to content

Instantly share code, notes, and snippets.

@mcleary
mcleary / Timer.cpp
Last active September 6, 2025 20:49
C++ Timer using std::chrono
#include <iostream>
#include <chrono>
#include <ctime>
#include <cmath>
class Timer
{
public:
void start()
{
/*
* Spinlock based on Qt atomic operations. Should be fairly portable.
* To use it, it is recommended to use the SpinLock::Acquire helper
* class to follow RAII patterns, e.g.:
*
* static SpinLock g_myLock;
* // ...
*
* void foo() {
* do_seomething();