PhoenixMicroBenchmark  1.3.0
Toolset for function micro-benchmarking
Loading...
Searching...
No Matches
PFunctionTimer_impl.h
Go to the documentation of this file.
1
2/***************************************
3 Auteur : Pierre Aubert
4 Mail : pierre.aubert@lapp.in2p3.fr
5 Licence : CeCILL-C
6****************************************/
7
8#ifndef __PFUNCTIONTIMER_IMPL_H__
9#define __PFUNCTIONTIMER_IMPL_H__
10
11#include "pin_thread_to_core.h"
12#include "micro_benchmark_ns.h"
13#include "PFunctionTimer.h"
14
16
18template <class T>
19[[gnu::always_inline]] inline void benchmark_doNotOptimize(T & value) {
20#if defined(__clang__)
21 asm volatile("" : "+r,m"(value) : : "memory");
22#else
23 asm volatile("" : "+m,r"(value) : : "memory");
24#endif
25}
26
28
32template<typename _Callable, typename... _Args>
33void PFunctionTimer::evalPerf(_Callable&& __f, _Args&&... __args){
35 int dummy = 0;
37 for(size_t i(0lu); i < p_nbMeasure; ++i){
38 //Start chrono
39 HiPeTime startNs = phoenix_getTime();
40 size_t startCy = phoenix_rdtsc();
41 //Call function
43 __f(__args...);
44 //Compute ellapsed time
45 size_t ellapsedTimeCy(phoenix_rdtsc() - startCy);
46 p_vecEllapsedTimeNs[i] = (double)ellapsedTimeCy;
47 NanoSecs elapsedTimeNs(phoenix_getTime() - startNs);
48 double fullNs((double)elapsedTimeNs.count());
49 p_vecEllapsedTimeCycle[i] = fullNs;
50 }
51}
52
53//{Finally we close the header :
54#endif
55
void benchmark_doNotOptimize(T &value)
Prevent compiler from optimising a loop.
std::vector< double > p_vecEllapsedTimeNs
Ellapsed time of the function in nanoseconds.
size_t p_nbMeasure
Number of performance measures we want on this function.
std::vector< double > p_vecEllapsedTimeCycle
Ellapsed time of the function in cycles.
void evalPerf(_Callable &&__f, _Args &&... __args)
Method which evaluate performance of the given function.
HiPeTime phoenix_getTime()
Get the current time.
std::chrono::nanoseconds NanoSecs
std::chrono::time_point< std::chrono::steady_clock > HiPeTime
long unsigned int phoenix_rdtsc(void)
#define PIN_THREAD_TO_CORE