PhoenixMicroBenchmark  1.0.1
Toolset for function micro-benchmarking
Loading...
Searching...
No Matches
micro_benchmark_common.cpp File Reference
#include <cmath>
#include <sstream>
#include "micro_benchmark_common.h"
+ Include dependency graph for micro_benchmark_common.cpp:

Go to the source code of this file.

Functions

std::vector< std::string > cutStringOnChars (const std::string &strIn, const std::string &setChars)
 Cut a string on determined chars.
 
bool findCharInString (const std::string &str, char ch)
 Tells if a chararacter is in a string.
 
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.
 
void micro_benchmarkHelpFunction ()
 Help function of the micro benchmarking program argument parse.
 
void micro_benchmarkHelpFunction2d ()
 Help function of the micro benchmarking program argument parse.
 
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.
 

Function Documentation

◆ cutStringOnChars()

std::vector< std::string > cutStringOnChars ( const std::string & strIn,
const std::string & setChars )

Cut a string on determined chars.

Parameters
strIn: input string
setChars: set of characters on which to cut
Returns
vector of cutted string

Definition at line 71 of file micro_benchmark_common.cpp.

71 {
72 std::vector<std::string> vecOut;
73 std::string strTmp("");
74 for(std::string::const_iterator it(strIn.begin()); it != strIn.end(); ++it){
75 if(findCharInString(setChars, *it)){
76 if(strTmp != ""){vecOut.push_back(strTmp);}
77 strTmp = "";
78 }else{
79 strTmp += *it;
80 }
81 }
82 if(strTmp != ""){vecOut.push_back(strTmp);}
83 return vecOut;
84}
bool findCharInString(const std::string &str, char ch)
Tells if a chararacter is in a string.

References findCharInString().

Referenced by micro_benchmarkParseArg(), and micro_benchmarkParseArg2d().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findCharInString()

bool findCharInString ( const std::string & str,
char ch )

Tells if a chararacter is in a string.

Parameters
str: string to be analysed
ch: char to be searched in str
Returns
true if ch is in str, false otherwise

Definition at line 57 of file micro_benchmark_common.cpp.

57 {
58 std::string::const_iterator it = str.begin();
59 while(it != str.end()){
60 if(*it == ch) return true;
61 ++it;
62 }
63 return false;
64}

Referenced by cutStringOnChars().

+ Here is the caller graph for this function:

◆ 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_benchmarkHelpFunction()

void micro_benchmarkHelpFunction ( )

Help function of the micro benchmarking program argument parse.

Definition at line 48 of file micro_benchmark_common.cpp.

48 {
49 std::cout << "micro_benchmarkParseArg : expect only a list of INT such as: \"1000,2000,3000,4000\"" << std::endl;
50}

Referenced by micro_benchmarkParseArg().

+ Here is the caller graph for this function:

◆ micro_benchmarkHelpFunction2d()

void micro_benchmarkHelpFunction2d ( )

Help function of the micro benchmarking program argument parse.

Definition at line 114 of file micro_benchmark_common.cpp.

114 {
115 std::cout << "micro_benchmarkParseArg2d : expect only two list of INT such as: \"1000,2000,3000,4000\"" << std::endl;
116}

Referenced by micro_benchmarkParseArg2d().

+ 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: