kvedala / function_timer

A wrapper around the CXX-11's `std::chrono` library to be used in C programs as well. This library provides a high-precision timer that can be utilized to measure precise execution times in a program.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

function_timer

A wrapper around the CXX-11's std::chrono library with high-precision timer to measure precise execution times in a program. The wrapper enables direct use in C and C++ programs.

Compile

The module is provided with a cmake build system. The compile sequence is:

mkdir build
cd build
cmake .. [-G <Generator>] [-DCMAKE_INSTALL_PREFIX=<install path>]
cmake --build . --config [Release/Debug]

This builds a static library function_timer that can be installed to the prefix using:

cmake --install .

APIs

The library, though written in C++, provides with C and a C++ interfaces.

C

  1. Include the header file function_timer.h
  2. Create the timer pointer instance
function_timer *timer = new_timer();
  1. Start timer instance
start_timer(timer);
  1. End timer & get the duration since timer start.
double duration = end_timer(timer);

If the end_timer function is called before calling the start_timer, the duration value is not guranteed to be 0 and will be invalid. There will not be any error messages.

  1. Delete the timer instance
delete_timer(timer);

C++

  1. Include the header file function_timer.h
  2. Create the timer pointer instance
function_timer *timer = new function_timer();
// or
function timer;
  1. Start timer instance
timer.start_timer();
  1. End timer & get the duration since timer start.
timer.end_timer();
double duration = timer.get_duration();

If the end_timer function is called before calling the start_timer, the duration value is not guranteed to be 0 and will be invalid. There will not be any error messages.

  1. If instantiated as a pointer, delete the timer instance
delete timer;   // iff timer is a pointer

Examples

Two sample implementations are provided as

  • test.c : test case in C
  • test.cpp : test case in C++

Note

To compile with C++, must enable the CXX-11 standard to account for std::chrono library.

About

A wrapper around the CXX-11's `std::chrono` library to be used in C programs as well. This library provides a high-precision timer that can be utilized to measure precise execution times in a program.

License:GNU General Public License v3.0


Languages

Language:C++ 61.2%Language:C 21.4%Language:CMake 17.4%