A simple C++ 03/11/etc timer class for ~microsecond-precision cross-platform benchmarking. The implementation is as limited and as simple as possible to create the lowest amount of overhead.

plf_nanotimer

A simple C++ 03/11/etc timer class for ~microsecond-precision cross-platform benchmarking. The implementation is as limited and simple as possible to afford the lowest amount of overhead.

Use as follows:

plf::nanotimer timer;


timer.start()

// Do something here

double results = timer.get_elapsed_ns();
std::cout << "Timing: " << results << " nanoseconds." << std::endl;


timer.start(); // "start" has the same semantics as "restart".

// Do something else

results = timer.get_elapsed_ms();
std::cout << "Timing: " << results << " milliseconds." << std::endl;


timer.start()

plf::microsecond_delay(15); // Delay program for 15 microseconds

results = timer.get_elapsed_us();
std::cout << "Timing: " << results << " microseconds." << std::endl;

Timer member functions:

void start(): start or restart timer

double get_elapsed_ns(): get elapsed time in nanoseconds

double get_elapsed_us(): get elapsed time in microseconds

double get_elapsed_ms(): get elapsed time in milliseconds

Non-member functions:

void plf::millisecond_delay(double x): delay the program until x milliseconds have passed

void plf::microsecond_delay(double x): delay the program until x microseconds have passed

void plf::nanosecond_delay(double x): delay the program until x nanoseconds have passed

Timer 'pausing':

I determined that a 'pause'-style function would add too much complexity to the class for simple benchmarking, which in turn might interfere with performance analysis, so if you need a 'pause' function do something like this:

plf::nanotimer timer;


timer.start()
// Do something here
double results = timer.get_elapsed_ns();

// Do something else - timer 'paused'

timer.start()

// Do stuff

results += timer.get_elapsed_ns();

std::cout << "Timing: " << results << " nanoseconds." << std::endl;
Similar Resources

🧪 single header unit testing framework for C and C++

🧪 utest.h A simple one header solution to unit testing for C/C++. Usage Just #include "utest.h" in your code! The current supported platforms are Lin

Dec 1, 2022

Anti-Debug and Anti-Memory Dump for Android

AntiDebugandMemoryDump Anti-Debug and Anti-Memory Dump for Android Some known techniques for anti-debug and anti-memory dump have been used in this pr

Nov 21, 2022

An efficient OpenFST-based tool for calculating WER and aligning two transcript sequences.

fstalign Overview Installation Dependencies Build Docker Quickstart WER Subcommand Align Subcommand Inputs Outputs Overview fstalign is a tool for cre

Nov 17, 2022

🍦IceCream-Cpp is a little (single header) library to help with the print debugging on C++11 and forward.

🍦IceCream-Cpp is a little (single header) library to help with the print debugging on C++11 and forward.

Nov 30, 2022

HyperDbg debugger is an open-source, hypervisor-assisted user-mode, and kernel-mode Windows debugger 🐞

HyperDbg debugger is an open-source, hypervisor-assisted user-mode, and kernel-mode Windows debugger 🐞

HyperDbg debugger is an open-source, hypervisor-assisted user-mode, and kernel-mode Windows debugger with a focus on using modern hardware technologies. It is a debugger designed for analyzing, fuzzing and reversing. 🐞

Nov 29, 2022

Watch for file changes and auto restart an application using fork checkpoints to continue the process (for quick live development)

Forkmon Watch for file changes and auto restart an application using fork checkpoints to continue. Intended for quick live development. This works onl

Aug 27, 2022

Palanteer is a set of high performance visual profiler, debugger, tests enabler for C++ and Python

Palanteer is a set of high performance visual profiler, debugger, tests enabler  for C++ and Python

Palanteer is a set of lean and efficient tools to improve the general software quality, for C++ and Python programs.

Nov 29, 2022

Hibizcus is a collection of tools - Font proofing and debugging tools

Hibizcus Font proofing and debugging tools. Written by: Muthu Nedumaran Hibizcus is a collection of tools written to proof and debug in-house develope

Oct 31, 2022

Windows-only Remote Access Tool (RAT) with anti-debugging and anti-sandbox checks

Windows-only Remote Access Tool (RAT) with anti-debugging and anti-sandbox checks

RATwurst Windows-only Remote Access Tool (RAT) with anti-debugging and anti-sandbox checks. For educational purposes only. The reason behind this proj

Nov 11, 2022
Comments
  • add inline to nanosecond_delay

    add inline to nanosecond_delay

    avoid possible multiple definition linker error

    Not sure why it was omitted, you might have a good reason. Let me know if there is more context of if I'm missing something.

  • ifdef and endif scope issue

    ifdef and endif scope issue

    At the end of the file, regarding the #endif that belongs to this #if:

    #if defined(MACH) || (defined(linux) || defined(linux) || defined(__linux)) || (defined(DragonFly) || defined(FreeBSD) || defined(NetBSD) || defined(OpenBSD)) || defined(_WIN32)

    it should be before "} // namespace", not after

A simple D3D11 Hook for x64 and x86 games. This project is ready to compile (x64 or x86).
A simple D3D11 Hook for x64 and x86 games. This project is ready to compile (x64 or x86).

D3D11Hook Features: Good Performance Simple, clean, GUI. Rendering using ImGui Clean code Easy to use with another project C++ 17 Xor String Ready to

Nov 10, 2022
Simple Unit Testing for C

Unity Test Copyright (c) 2007 - 2021 Unity Project by Mike Karlesky, Mark VanderVoord, and Greg Williams Welcome to the Unity Test Project, one of the

Nov 24, 2022
Simple Android ARM&ARM64 GOT Hook

Simple Android ARM&ARM64 GOT Hook 基于链接视图和执行视图,解析ELF,查找导入函数偏移值,替换函数地址。 详见:简易Android ARM&ARM64 GOT Hook (一) 简易Android ARM&ARM64 GOT Hook (二) 编译 使用Androi

Nov 11, 2022
A simple framework for compile-time benchmarks

Metabench A simple framework for compile-time microbenchmarks Overview Metabench is a single, self-contained CMake module making it easy to create com

Oct 23, 2022
A modern, C++-native, header-only, test framework for unit-tests, TDD and BDD - using C++11, C++14, C++17 and later (or C++03 on the Catch1.x branch)
A modern, C++-native, header-only, test framework for unit-tests, TDD and BDD - using C++11, C++14, C++17 and later (or C++03 on the Catch1.x branch)

Catch2 v3 is being developed! You are on the devel branch, where the next major version, v3, of Catch2 is being developed. As it is a significant rewo

Nov 25, 2022
A modern, C++-native, header-only, test framework for unit-tests, TDD and BDD - using C++11, C++14, C++17 and later (or C++03 on the Catch1.x branch)
A modern, C++-native, header-only, test framework for unit-tests, TDD and BDD - using C++11, C++14, C++17 and later (or C++03 on the Catch1.x branch)

Catch2 v3 is being developed! You are on the devel branch, where the next major version, v3, of Catch2 is being developed. As it is a significant rewo

Nov 24, 2022
DotX64Dbg aims to provide a seamless way to write and test plugins for X64Dbg using .Net 5.0 and C#.
DotX64Dbg aims to provide a seamless way to write and test plugins for X64Dbg using .Net 5.0 and C#.

DotX64Dbg (EARLY ALPHA) Plugins and Scripting with C# for x64Dbg. Create Plugins for X64Dbg with ease DotX64Dbg aims to provide a seamless way to writ

Oct 16, 2022
The world's first free and open-source PlayStation 3 emulator/debugger, written in C++ for Windows and Linux.

The world's first free and open-source PlayStation 3 emulator/debugger, written in C++ for Windows and Linux.

Dec 1, 2022
CppUTest unit testing and mocking framework for C/C++

CppUTest CppUTest unit testing and mocking framework for C/C++ More information on the project page Slack channel: Join if link not expired Getting St

Nov 26, 2022
Googletest - Google Testing and Mocking Framework

GoogleTest OSS Builds Status Announcements Release 1.10.x Release 1.10.x is now available. Coming Soon Post 1.10.x googletest will follow Abseil Live

Nov 25, 2022