| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include <cmath> | ||
| 8 | #include <sstream> | ||
| 9 | #include "micro_benchmark_common.h" | ||
| 10 | |||
| 11 | ///Fill the map of ordered time with the vector | ||
| 12 | /** @param[out] mapOrderTime : map of the ordered ellapsed times | ||
| 13 | * @param vecTime : input ellapsed times | ||
| 14 | */ | ||
| 15 | 382 | void micro_benchmarkVecToMap(MapOrderedTime & mapOrderTime, const VecEllapsedTime & vecTime){ | |
| 16 |
2/2✓ Branch 0 (25→3) taken 62320 times.
✓ Branch 1 (25→26) taken 382 times.
|
125404 | for(VecEllapsedTime::const_iterator it(vecTime.begin()); it != vecTime.end(); ++it){ |
| 17 |
1/1✓ Branch 0 (5→6) taken 62320 times.
|
62320 | MapOrderedTime::iterator itFindTime = mapOrderTime.find(*it); |
| 18 |
2/2✓ Branch 0 (8→9) taken 28268 times.
✓ Branch 1 (8→11) taken 34052 times.
|
62320 | if(itFindTime != mapOrderTime.end()){ |
| 19 | 28268 | itFindTime->second += 1lu; | |
| 20 | }else{ | ||
| 21 |
1/1✓ Branch 0 (13→14) taken 34052 times.
|
34052 | mapOrderTime[*it] = 1lu; |
| 22 | } | ||
| 23 | } | ||
| 24 | 382 | } | |
| 25 | |||
| 26 | ///Compute the total computing time and associated error with the given data | ||
| 27 | /** @param[out] ellapsedTimeNs : ellapsed time in ns | ||
| 28 | * @param[out] ellapsedTimeErrorNs : error on the ellapsed time in ns | ||
| 29 | * @param mapOrderTime : map of the ordered ellapsed times | ||
| 30 | * @param nbValueToBeUsed : number of values to be used in the map to compute the performance of the function | ||
| 31 | */ | ||
| 32 | 382 | void micro_benchmarkComputeTime(double & ellapsedTimeNs, double & ellapsedTimeErrorNs, const MapOrderedTime & mapOrderTime, size_t nbValueToBeUsed){ | |
| 33 | 382 | double sumValue(0.0), sumSquare(0.0); | |
| 34 | 382 | size_t nbValue(0lu); | |
| 35 |
5/6✓ Branch 0 (10→11) taken 22501 times.
✗ Branch 1 (10→13) not taken.
✓ Branch 2 (11→12) taken 22119 times.
✓ Branch 3 (11→13) taken 382 times.
✓ Branch 4 (14→3) taken 22119 times.
✓ Branch 5 (14→15) taken 382 times.
|
22501 | for(MapOrderedTime::const_iterator it(mapOrderTime.begin()); it != mapOrderTime.end() && nbValue < nbValueToBeUsed; ++it){ |
| 36 | 22119 | double val(it->first); | |
| 37 | |||
| 38 | 22119 | sumValue += val*((double)it->second); | |
| 39 | 22119 | sumSquare += val*val*((double)it->second); | |
| 40 | 22119 | nbValue += it->second; | |
| 41 | } | ||
| 42 | 382 | ellapsedTimeNs = sumValue/((double)nbValue); | |
| 43 | 382 | double meanSquare(sumSquare/((double)nbValue)); | |
| 44 | 382 | ellapsedTimeErrorNs = std::sqrt(meanSquare - ellapsedTimeNs*ellapsedTimeNs); | |
| 45 | 382 | } | |
| 46 | |||
| 47 | ///Help function of the micro benchmarking program argument parse | ||
| 48 | 2 | void micro_benchmarkHelpFunction(){ | |
| 49 | 2 | std::cout << "micro_benchmarkParseArg : expect only a list of INT such as: \"1000,2000,3000,4000\"" << std::endl; | |
| 50 | 2 | } | |
| 51 | |||
| 52 | ///Tells if a chararacter is in a string | ||
| 53 | /** @param str : string to be analysed | ||
| 54 | * @param ch : char to be searched in str | ||
| 55 | * @return true if ch is in str, false otherwise | ||
| 56 | */ | ||
| 57 | 847 | bool findCharInString(const std::string& str, char ch){ | |
| 58 | 847 | std::string::const_iterator it = str.begin(); | |
| 59 |
2/2✓ Branch 0 (18→4) taken 2797 times.
✓ Branch 1 (18→19) taken 650 times.
|
6894 | while(it != str.end()){ |
| 60 |
2/2✓ Branch 0 (6→7) taken 197 times.
✓ Branch 1 (6→8) taken 2600 times.
|
2797 | if(*it == ch) return true; |
| 61 | ++it; | ||
| 62 | } | ||
| 63 | 650 | return false; | |
| 64 | } | ||
| 65 | |||
| 66 | ///Cut a string on determined chars | ||
| 67 | /** @param strIn : input string | ||
| 68 | * @param setChars : set of characters on which to cut | ||
| 69 | * @return vector of cutted string | ||
| 70 | */ | ||
| 71 | 42 | std::vector<std::string> cutStringOnChars(const std::string & strIn, const std::string & setChars){ | |
| 72 | 42 | std::vector<std::string> vecOut; | |
| 73 |
1/1✓ Branch 0 (5→6) taken 42 times.
|
42 | std::string strTmp(""); |
| 74 |
2/2✓ Branch 0 (29→8) taken 847 times.
✓ Branch 1 (29→30) taken 42 times.
|
1778 | for(std::string::const_iterator it(strIn.begin()); it != strIn.end(); ++it){ |
| 75 |
3/3✓ Branch 0 (10→11) taken 847 times.
✓ Branch 2 (11→12) taken 197 times.
✓ Branch 3 (11→16) taken 650 times.
|
847 | if(findCharInString(setChars, *it)){ |
| 76 |
3/4✓ Branch 0 (12→13) taken 197 times.
✓ Branch 2 (13→14) taken 197 times.
✗ Branch 3 (13→15) not taken.
✓ Branch 4 (14→15) taken 197 times.
|
197 | if(strTmp != ""){vecOut.push_back(strTmp);} |
| 77 |
1/1✓ Branch 0 (15→19) taken 197 times.
|
197 | strTmp = ""; |
| 78 | }else{ | ||
| 79 |
1/1✓ Branch 0 (18→19) taken 650 times.
|
650 | strTmp += *it; |
| 80 | } | ||
| 81 | } | ||
| 82 |
3/4✓ Branch 0 (30→31) taken 42 times.
✓ Branch 2 (31→32) taken 42 times.
✗ Branch 3 (31→33) not taken.
✓ Branch 4 (32→33) taken 42 times.
|
42 | if(strTmp != ""){vecOut.push_back(strTmp);} |
| 83 | 42 | return vecOut; | |
| 84 | 42 | } | |
| 85 | |||
| 86 | ///Call the evalFunc by respect to the arguments given to the program | ||
| 87 | /** @param argc : number of arguments passed to the program | ||
| 88 | * @param argv : table of arguments passed to the program | ||
| 89 | * @param evalFunc : function which evaluates the performance of an other function | ||
| 90 | * @return 0 on success, -1 otherwise | ||
| 91 | */ | ||
| 92 | 34 | int micro_benchmarkParseArg(int argc, char** argv, EvaluateTimeFct evalFunc){ | |
| 93 |
2/3✓ Branch 0 (2→3) taken 34 times.
✗ Branch 2 (3→4) not taken.
✓ Branch 3 (3→5) taken 34 times.
|
34 | PIN_THREAD_TO_CORE |
| 94 |
2/2✓ Branch 0 (5→6) taken 1 times.
✓ Branch 1 (5→8) taken 33 times.
|
34 | if(argc != 2){ |
| 95 |
1/1✓ Branch 0 (6→7) taken 1 times.
|
1 | micro_benchmarkHelpFunction(); |
| 96 | 1 | return -1; | |
| 97 | } | ||
| 98 |
1/1✓ Branch 0 (10→11) taken 33 times.
|
33 | std::string argument(argv[1]); |
| 99 |
7/8✓ Branch 0 (12→13) taken 33 times.
✓ Branch 2 (13→14) taken 32 times.
✓ Branch 3 (13→16) taken 1 times.
✓ Branch 4 (14→15) taken 32 times.
✗ Branch 6 (15→16) not taken.
✓ Branch 7 (15→17) taken 32 times.
✓ Branch 8 (18→19) taken 1 times.
✓ Branch 9 (18→21) taken 32 times.
|
33 | if(argument == "--help" || argument == "-h"){ |
| 100 |
1/1✓ Branch 0 (19→20) taken 1 times.
|
1 | micro_benchmarkHelpFunction(); |
| 101 | 1 | return 0; | |
| 102 | } | ||
| 103 |
2/2✓ Branch 0 (23→24) taken 32 times.
✓ Branch 2 (24→25) taken 32 times.
|
32 | std::vector<std::string> vecSize(cutStringOnChars(argument, ", \t\n")); |
| 104 |
2/2✓ Branch 0 (45→28) taken 192 times.
✓ Branch 1 (45→46) taken 32 times.
|
448 | for(std::vector<std::string>::iterator it(vecSize.begin()); it != vecSize.end(); ++it){ |
| 105 |
1/1✓ Branch 0 (31→32) taken 192 times.
|
384 | std::stringstream converterStr(*it); |
| 106 | 192 | size_t nbElement(0lu); | |
| 107 |
1/1✓ Branch 0 (32→33) taken 192 times.
|
192 | converterStr >> nbElement; |
| 108 |
1/1✓ Branch 0 (33→34) taken 192 times.
|
192 | evalFunc(nbElement); |
| 109 | 192 | } | |
| 110 | 32 | return 0; | |
| 111 | 33 | } | |
| 112 | |||
| 113 | ///Help function of the micro benchmarking program argument parse | ||
| 114 | 1 | void micro_benchmarkHelpFunction2d(){ | |
| 115 | 1 | std::cout << "micro_benchmarkParseArg2d : expect only two list of INT such as: \"1000,2000,3000,4000\"" << std::endl; | |
| 116 | 1 | } | |
| 117 | |||
| 118 | ///Call the evalFunc by respect to the arguments given to the program | ||
| 119 | /** @param argc : number of arguments passed to the program | ||
| 120 | * @param argv : table of arguments passed to the program | ||
| 121 | * @param evalFunc : function which evaluates the performance of an other function | ||
| 122 | * @return 0 on success, -1 otherwise | ||
| 123 | */ | ||
| 124 | 6 | int micro_benchmarkParseArg2d(int argc, char** argv, EvaluateTimeFct2d evalFunc){ | |
| 125 |
2/3✓ Branch 0 (2→3) taken 6 times.
✗ Branch 2 (3→4) not taken.
✓ Branch 3 (3→5) taken 6 times.
|
6 | PIN_THREAD_TO_CORE |
| 126 |
2/2✓ Branch 0 (5→6) taken 1 times.
✓ Branch 1 (5→8) taken 5 times.
|
6 | if(argc != 3){ |
| 127 |
1/1✓ Branch 0 (6→7) taken 1 times.
|
1 | micro_benchmarkHelpFunction2d(); |
| 128 | 1 | return -1; | |
| 129 | } | ||
| 130 |
2/2✓ Branch 0 (10→11) taken 5 times.
✓ Branch 2 (14→15) taken 5 times.
|
20 | std::string argumentX(argv[1]), argumentY(argv[2]); |
| 131 | |||
| 132 |
2/2✓ Branch 0 (18→19) taken 5 times.
✓ Branch 2 (19→20) taken 5 times.
|
10 | std::vector<std::string> vecSizeX(cutStringOnChars(argumentX, ", \t\n")); |
| 133 |
2/2✓ Branch 0 (24→25) taken 5 times.
✓ Branch 2 (25→26) taken 5 times.
|
5 | std::vector<std::string> vecSizeY(cutStringOnChars(argumentY, ", \t\n")); |
| 134 |
2/2✓ Branch 0 (30→31) taken 1 times.
✓ Branch 1 (30→48) taken 4 times.
|
5 | if(vecSizeX.size() != vecSizeY.size()){ |
| 135 |
6/6✓ Branch 0 (31→32) taken 1 times.
✓ Branch 2 (33→34) taken 1 times.
✓ Branch 4 (34→35) taken 1 times.
✓ Branch 6 (36→37) taken 1 times.
✓ Branch 8 (37→38) taken 1 times.
✓ Branch 10 (38→39) taken 1 times.
|
1 | std::cerr << "Vector X and Y must ave the same size vecSizeX("<<vecSizeX.size()<<") != vecSizeY("<<vecSizeY.size()<<")" << std::endl; |
| 136 |
6/6✓ Branch 0 (39→40) taken 1 times.
✓ Branch 2 (41→42) taken 1 times.
✓ Branch 4 (42→43) taken 1 times.
✓ Branch 6 (44→45) taken 1 times.
✓ Branch 8 (45→46) taken 1 times.
✓ Branch 10 (46→47) taken 1 times.
|
1 | std::cout << "Vector X and Y must ave the same size vecSizeX("<<vecSizeX.size()<<") != vecSizeY("<<vecSizeY.size()<<")" << std::endl; |
| 137 | 1 | return -1; | |
| 138 | } | ||
| 139 |
2/2✓ Branch 0 (67→49) taken 21 times.
✓ Branch 1 (67→68) taken 4 times.
|
50 | for(std::vector<std::string>::iterator itX(vecSizeX.begin()); itX != vecSizeX.end(); ++itX){ |
| 140 |
1/1✓ Branch 0 (52→53) taken 21 times.
|
42 | std::stringstream converterStrX(*itX); |
| 141 | 21 | size_t nbElementX(0lu); | |
| 142 |
1/1✓ Branch 0 (53→54) taken 21 times.
|
21 | converterStrX >> nbElementX; |
| 143 |
2/2✓ Branch 0 (54→55) taken 21 times.
✓ Branch 2 (55→56) taken 21 times.
|
21 | std::cout << "\t" << nbElementX; |
| 144 | 21 | } | |
| 145 |
1/1✓ Branch 0 (68→69) taken 4 times.
|
4 | std::cout << std::endl; |
| 146 | |||
| 147 |
2/2✓ Branch 0 (116→70) taken 21 times.
✓ Branch 1 (116→117) taken 4 times.
|
50 | for(std::vector<std::string>::iterator itY(vecSizeY.begin()); itY != vecSizeY.end(); ++itY){ |
| 148 |
1/1✓ Branch 0 (73→74) taken 21 times.
|
42 | std::stringstream converterStrY(*itY); |
| 149 | 21 | size_t nbElementY(0lu); | |
| 150 |
1/1✓ Branch 0 (74→75) taken 21 times.
|
21 | converterStrY >> nbElementY; |
| 151 |
1/1✓ Branch 0 (75→76) taken 21 times.
|
21 | std::cout << nbElementY; |
| 152 |
2/2✓ Branch 0 (102→77) taken 117 times.
✓ Branch 1 (102→103) taken 21 times.
|
276 | for(std::vector<std::string>::iterator itX(vecSizeX.begin()); itX != vecSizeX.end(); ++itX){ |
| 153 |
1/1✓ Branch 0 (80→81) taken 117 times.
|
234 | std::stringstream converterStrX(*itX); |
| 154 | 117 | size_t nbElementX(0lu); | |
| 155 |
1/1✓ Branch 0 (81→82) taken 117 times.
|
117 | converterStrX >> nbElementX; |
| 156 |
1/1✓ Branch 0 (82→83) taken 117 times.
|
117 | double res = evalFunc(nbElementX, nbElementY); |
| 157 |
6/6✓ Branch 0 (83→84) taken 117 times.
✓ Branch 2 (84→85) taken 117 times.
✓ Branch 4 (85→86) taken 117 times.
✓ Branch 6 (86→87) taken 117 times.
✓ Branch 8 (87→88) taken 117 times.
✓ Branch 10 (88→89) taken 117 times.
|
117 | std::cerr << nbElementX << "\t" << nbElementY << "\t" << res << std::endl; |
| 158 |
2/2✓ Branch 0 (89→90) taken 117 times.
✓ Branch 2 (90→91) taken 117 times.
|
117 | std::cout << "\t" << res; |
| 159 | 117 | } | |
| 160 |
1/1✓ Branch 0 (103→104) taken 21 times.
|
21 | std::cerr << std::endl; |
| 161 |
1/1✓ Branch 0 (104→105) taken 21 times.
|
21 | std::cout << std::endl; |
| 162 | 21 | } | |
| 163 | 4 | return 0; | |
| 164 | 5 | } | |
| 165 | |||
| 166 | |||
| 167 | |||
| 168 |