Skip to content

Veng97/scoped-timers

Repository files navigation

Scoped Timers

CI

A simple C++ library providing RAII-style scoped timers for performance measurement.

Usage

#include "scoped_timers/scoped_timers.hpp"
#include "scoped_timers/utils.hpp" // For printing utility functions

#include <chrono>
#include <iostream>
#include <thread>

int main()
{

  for (int i = 0; i < 300; ++i) {
    {
      ScopedTimers::Timer timer("Timers/First");
      std::this_thread::sleep_for(std::chrono::duration<double>(0.00723));
    }
    {
      ScopedTimers::Timer timer("Timers/Second");
      std::this_thread::sleep_for(std::chrono::duration<double>(0.00234));
    }
    {
      ScopedTimers::Timer timer("Timers/Third");
      std::this_thread::sleep_for(std::chrono::duration<double>(0.000345));
    }
  }

  // Print timer statistics
  std::cout << ScopedTimers::Registry::getTimingTable();
}

Building

mkdir build
cd build
cmake ..
cmake --build .

Testing

Tests are built using Catch2 and can be run with:

cd build
ctest --output-on-failure

License

MIT

About

Provides scoped timers for C++ to measure duration/interval of code being called

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •