Home

PLF C++ Library - plf::nanotimer

Intro

plf::nanotimer is a simple C++03/11/etc timer class for ~microsecond-precision cross-platform benchmarking. As a result the implementation is as limited and simple as possible to create the lowest amount of overhead. It was primarily constructed because cross-compiler support for sub-timeslice timer readings using std::chrono was lacking, and boost::chrono does not give sub-timeslice readings on all versions of windows. Also included in the header are some additional 'delay' functions.

Implementation

plf::nanotimer uses QPC under Windows (see this post for it's resolution and quirks), clock_get_time under Mac OSX, and clock_gettime (with CLOCK_MONOTONIC) under Linux/BSD. Windows XP is supported but see the article above for it's failings under that platform. The timer does not in fact 'count' the time - it takes a measurement when the timer is started, then again when a function to measure the elapsed time has passed. The timer can be 'paused/unpaused' by taking a reading of the current elapsed time when you want to pause, then calling 'start' again when it's time to unpause (this resets the timer). At the next reading of elapsed time, simply add to the previous reading.

License

plf::nanotimer is under a permissive zlib license. This means: Software is used on 'as-is' basis. It can be modified and used in commercial software. Authors are not liable for any damages arising from its use. The distribution of a modified version of the software is subject to the following restrictions:

Download

Download here (3kb zip file) or view the repository.
plf::nanotimer is a simple .h header-only library, to be used with an #include command.

Function Descriptions and syntax

Constructor

Member functions

Non-member functions which utilize plf::nanotimer

Version history

Contact: footer
plf:: library and this page Copyright (c) 2017, Matthew Bentley