Timing library for performance test

Timing library for prototyping performance

The aim of this library is to provide the most accurate timing system to know how long last a function or a portion of code. It is totaly automated and have some several custom behaviour.

Use of 3 different timing methods: RDTSC,RDTSCP or std::chrono. Theses timers can be used in different situations.
RDTSCP timer is only available on at least Pentium III and wait for all previous instruction to be executed aka when the instruction pipeline is empty.

RDTSC timer is only available on at least Pentium III and do not wait for all previous instruction to be executed aka when the instruction pipeline is empty.

std::chrono uses the standard timer , and it is compatible on all platforms.

The API is composed of 5 methods:

timing::addFunction (string name,function pointer to time) : add to test framework the function identified by the name (the name can be any string as it is only used to identify function during results printing)

timing::setTimingFunction : set the method used to calculate the timing

timing::setNumberExecution : set the number of time the function has to be executed

0: RDTSC
1: RDTSCP
2: RDTSC and RDTSCP
3: std::chrono
99: all methods

timing::Execute: execute all function added with addFunction , you can pass an int if needed

timing::CalcResult: summarize all executions  and print all results

Tips: When using RDTSC, RDTSCP or sdt::chrono ?

As RDTSC and RDTSCP are quite equivalent prefer using RDTSCP  when your are testing very short function with memory access. By purging the pipeline before, It will give a more precise view of the performance.
Use std::chrono when you are not on Pentium IV architecture or if you are testing long functions or function that involve mutl-core or multi-threading architecture

Exemple of use:

int main(int argc, char **argv)
{
      timing::addFunction("FIB", fibonacci);
      timing::addFunction("FIB-OPTIM", fibonacciOptim);
      timing::setTimingFunction(0);
      timing::setNumberExecution(1);
      timing::execute(40);
      timing::CalcResult();
}

Library example :

git clone https://github.com/fflayol/timingperf.git
cd timingperf

;this command is optional, it will copy the file performancetiming.hpp to /usr/local/include
make install 

make
./ex1.out