PhoenixMicroBenchmark  1.0.1
Toolset for function micro-benchmarking
Loading...
Searching...
No Matches
micro_benchmark_common.h File Reference
#include <chrono>
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include "pin_thread_to_core.h"
+ Include dependency graph for micro_benchmark_common.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(& EvaluateTimeFct) (size_t)
 
typedef double(& EvaluateTimeFct2d) (size_t, size_t)
 
typedef std::map< double, size_t > MapOrderedTime
 Map of the ordered ellapsed time.
 
typedef std::vector< double > VecEllapsedTime
 Vector of ellapsed time measurement.
 

Functions

void micro_benchmarkComputeTime (double &ellapsedTimeNs, double &ellapsedTimeErrorNs, const MapOrderedTime &mapOrderTime, size_t nbValueToBeUsed)
 Compute the total computing time and associated error with the given data.
 
int micro_benchmarkParseArg (int argc, char **argv, EvaluateTimeFct evalFunc)
 Call the evalFunc by respect to the arguments given to the program.
 
int micro_benchmarkParseArg2d (int argc, char **argv, EvaluateTimeFct2d evalFunc)
 Call the evalFunc by respect to the arguments given to the program.
 
void micro_benchmarkVecToMap (MapOrderedTime &mapOrderTime, const VecEllapsedTime &vecTime)
 Fill the map of ordered time with the vector.
 

Typedef Documentation

◆ EvaluateTimeFct

typedef void(& EvaluateTimeFct) (size_t)

Definition at line 23 of file micro_benchmark_common.h.

◆ EvaluateTimeFct2d

typedef double(& EvaluateTimeFct2d) (size_t, size_t)

Definition at line 24 of file micro_benchmark_common.h.

◆ MapOrderedTime

typedef std::map<double, size_t> MapOrderedTime

Map of the ordered ellapsed time.

Definition at line 21 of file micro_benchmark_common.h.

◆ VecEllapsedTime

typedef std::vector<double> VecEllapsedTime

Vector of ellapsed time measurement.

Definition at line 19 of file micro_benchmark_common.h.

Function Documentation

◆ micro_benchmarkComputeTime()

void micro_benchmarkComputeTime ( double & ellapsedTimeNs,
double & ellapsedTimeErrorNs,
const MapOrderedTime & mapOrderTime,
size_t nbValueToBeUsed )

Compute the total computing time and associated error with the given data.

Parameters
[out]ellapsedTimeNs: ellapsed time in ns
[out]ellapsedTimeErrorNs: error on the ellapsed time in ns
mapOrderTime: map of the ordered ellapsed times
nbValueToBeUsed: number of values to be used in the map to compute the performance of the function

Definition at line 32 of file micro_benchmark_common.cpp.

32 {
33 double sumValue(0.0), sumSquare(0.0);
34 size_t nbValue(0lu);
35 for(MapOrderedTime::const_iterator it(mapOrderTime.begin()); it != mapOrderTime.end() && nbValue < nbValueToBeUsed; ++it){
36 double val(it->first);
37
38 sumValue += val*((double)it->second);
39 sumSquare += val*val*((double)it->second);
40 nbValue += it->second;
41 }
42 ellapsedTimeNs = sumValue/((double)nbValue);
43 double meanSquare(sumSquare/((double)nbValue));
44 ellapsedTimeErrorNs = std::sqrt(meanSquare - ellapsedTimeNs*ellapsedTimeNs);
45}

Referenced by micro_benchmarkNs(), and micro_benchmarkRdtsc().

+ Here is the caller graph for this function:

◆ micro_benchmarkParseArg()

int micro_benchmarkParseArg ( int argc,
char ** argv,
EvaluateTimeFct evalFunc )

Call the evalFunc by respect to the arguments given to the program.

Parameters
argc: number of arguments passed to the program
argv: table of arguments passed to the program
evalFunc: function which evaluates the performance of an other function
Returns
0 on success, -1 otherwise

Definition at line 92 of file micro_benchmark_common.cpp.

92 {
94 if(argc != 2){
96 return -1;
97 }
98 std::string argument(argv[1]);
99 if(argument == "--help" || argument == "-h"){
101 return 0;
102 }
103 std::vector<std::string> vecSize(cutStringOnChars(argument, ", \t\n"));
104 for(std::vector<std::string>::iterator it(vecSize.begin()); it != vecSize.end(); ++it){
105 std::stringstream converterStr(*it);
106 size_t nbElement(0lu);
107 converterStr >> nbElement;
108 evalFunc(nbElement);
109 }
110 return 0;
111}
void micro_benchmarkHelpFunction()
Help function of the micro benchmarking program argument parse.
std::vector< std::string > cutStringOnChars(const std::string &strIn, const std::string &setChars)
Cut a string on determined chars.
#define PIN_THREAD_TO_CORE

References cutStringOnChars(), micro_benchmarkHelpFunction(), and PIN_THREAD_TO_CORE.

+ Here is the call graph for this function:

◆ micro_benchmarkParseArg2d()

int micro_benchmarkParseArg2d ( int argc,
char ** argv,
EvaluateTimeFct2d evalFunc )

Call the evalFunc by respect to the arguments given to the program.

Parameters
argc: number of arguments passed to the program
argv: table of arguments passed to the program
evalFunc: function which evaluates the performance of an other function
Returns
0 on success, -1 otherwise

Definition at line 124 of file micro_benchmark_common.cpp.

124 {
126 if(argc != 3){
128 return -1;
129 }
130 std::string argumentX(argv[1]), argumentY(argv[2]);
131
132 std::vector<std::string> vecSizeX(cutStringOnChars(argumentX, ", \t\n"));
133 std::vector<std::string> vecSizeY(cutStringOnChars(argumentY, ", \t\n"));
134 if(vecSizeX.size() != vecSizeY.size()){
135 std::cerr << "Vector X and Y must ave the same size vecSizeX("<<vecSizeX.size()<<") != vecSizeY("<<vecSizeY.size()<<")" << std::endl;
136 std::cout << "Vector X and Y must ave the same size vecSizeX("<<vecSizeX.size()<<") != vecSizeY("<<vecSizeY.size()<<")" << std::endl;
137 return -1;
138 }
139 for(std::vector<std::string>::iterator itX(vecSizeX.begin()); itX != vecSizeX.end(); ++itX){
140 std::stringstream converterStrX(*itX);
141 size_t nbElementX(0lu);
142 converterStrX >> nbElementX;
143 std::cout << "\t" << nbElementX;
144 }
145 std::cout << std::endl;
146
147 for(std::vector<std::string>::iterator itY(vecSizeY.begin()); itY != vecSizeY.end(); ++itY){
148 std::stringstream converterStrY(*itY);
149 size_t nbElementY(0lu);
150 converterStrY >> nbElementY;
151 std::cout << nbElementY;
152 for(std::vector<std::string>::iterator itX(vecSizeX.begin()); itX != vecSizeX.end(); ++itX){
153 std::stringstream converterStrX(*itX);
154 size_t nbElementX(0lu);
155 converterStrX >> nbElementX;
156 double res = evalFunc(nbElementX, nbElementY);
157 std::cerr << nbElementX << "\t" << nbElementY << "\t" << res << std::endl;
158 std::cout << "\t" << res;
159 }
160 std::cerr << std::endl;
161 std::cout << std::endl;
162 }
163 return 0;
164}
void micro_benchmarkHelpFunction2d()
Help function of the micro benchmarking program argument parse.

References cutStringOnChars(), micro_benchmarkHelpFunction2d(), and PIN_THREAD_TO_CORE.

+ Here is the call graph for this function:

◆ micro_benchmarkVecToMap()

void micro_benchmarkVecToMap ( MapOrderedTime & mapOrderTime,
const VecEllapsedTime & vecTime )

Fill the map of ordered time with the vector.

Parameters
[out]mapOrderTime: map of the ordered ellapsed times
vecTime: input ellapsed times

Definition at line 15 of file micro_benchmark_common.cpp.

15 {
16 for(VecEllapsedTime::const_iterator it(vecTime.begin()); it != vecTime.end(); ++it){
17 MapOrderedTime::iterator itFindTime = mapOrderTime.find(*it);
18 if(itFindTime != mapOrderTime.end()){
19 itFindTime->second += 1lu;
20 }else{
21 mapOrderTime[*it] = 1lu;
22 }
23 }
24}

Referenced by micro_benchmarkNs(), and micro_benchmarkRdtsc().

+ Here is the caller graph for this function: