GCC Code Coverage Report


Directory: ./
File: src/micro_benchmark_rdtsc_impl.h
Date: 2025-11-27 16:24:10
Exec Total Coverage
Lines: 26 27 96.3%
Functions: 3 3 100.0%
Branches: 34 35 97.1%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #ifndef __MICRO_BENCHMARK_RDTSC_IMPL_H__
8 #define __MICRO_BENCHMARK_RDTSC_IMPL_H__
9
10 #include "phoenix_timer.h"
11 #include "micro_benchmark_rdtsc.h"
12
13 ///Do the micro benchmarking of a given function and gives performance results in cy
14 /** @param[out] ellapsedTimeCy : ellapsed time in cy
15 * @param[out] ellapsedTimeErrorCy : error on the ellapsed time in cy
16 * @param nbTestPerf : number of performance test
17 * @param nbCallPerTest : number of calls per performance test
18 * @param __f : function to be called and benchmarked
19 * @param __args : parameter of the function to be benchmarked
20 */
21 template<typename _Callable, typename... _Args>
22 30 void micro_benchmarkRdtsc(double & ellapsedTimeCy, double & ellapsedTimeErrorCy, size_t nbTestPerf, size_t nbCallPerTest,
23 _Callable&& __f, _Args&&... __args)
24 {
25 30 VecEllapsedTime vecTimeCy;
26
2/2
✓ Branch 0 (12→4) taken 12000 times.
✓ Branch 1 (12→13) taken 30 times.
12030 for(size_t i(0lu); i < nbTestPerf; ++i){
27 //Stating the timer
28
1/1
✓ Branch 0 (4→5) taken 12000 times.
12000 size_t beginTime = phoenix_rdtsc();
29
2/2
✓ Branch 0 (8→6) taken 7200000 times.
✓ Branch 1 (8→9) taken 12000 times.
7212000 for(size_t j(0lu); j < nbCallPerTest; ++j){
30
1/1
✓ Branch 0 (6→7) taken 7200000 times.
7200000 __f(__args...);
31 }
32 //Get the time of the nbCallPerTest calls
33
1/1
✓ Branch 0 (9→10) taken 12000 times.
12000 size_t elapsedTime(phoenix_rdtsc() - beginTime);
34 12000 double fullCy(elapsedTime/((double)nbCallPerTest));
35
1/1
✓ Branch 0 (10→11) taken 12000 times.
12000 vecTimeCy.push_back(fullCy);
36 }
37 30 MapOrderedTime mapOrderTime;
38
1/1
✓ Branch 0 (14→15) taken 30 times.
30 micro_benchmarkVecToMap(mapOrderTime, vecTimeCy);
39 30 size_t nbValueUsed(vecTimeCy.size()*0.7 + 1lu);
40
1/2
✗ Branch 0 (17→18) not taken.
✓ Branch 1 (17→19) taken 30 times.
30 if(nbValueUsed > vecTimeCy.size()){
41 nbValueUsed = vecTimeCy.size();
42 }
43
1/1
✓ Branch 0 (19→20) taken 30 times.
30 micro_benchmarkComputeTime(ellapsedTimeCy, ellapsedTimeErrorCy, mapOrderTime, nbValueUsed);
44 30 }
45
46 ///Do the micro benchmarking of a given function and gives performance results in cy
47 /** @param[out] ellapsedTimeCy : ellapsed time in cy
48 * @param[out] ellapsedTimeErrorCy : error on the ellapsed time in cy
49 * @param[out] timePerElement : time per element in cy
50 * @param[out] timeErrorPerElement : error of time per element in cy
51 * @param nbTestPerf : number of performance test
52 * @param nbCallPerTest : number of calls per performance test
53 * @param nbElement : number of element treated by the function __f
54 * @param __f : function to be called and benchmarked
55 * @param __args : parameter of the function to be benchmarked
56 */
57 template<typename _Callable, typename... _Args>
58 30 void micro_benchmarkRdtsc(double & ellapsedTimeCy, double & ellapsedTimeErrorCy,
59 double & timePerElement, double & timeErrorPerElement, size_t nbTestPerf, size_t nbCallPerTest, size_t nbElement,
60 _Callable&& __f, _Args&&... __args)
61 {
62 30 micro_benchmarkRdtsc(ellapsedTimeCy, ellapsedTimeErrorCy, nbTestPerf, nbCallPerTest, __f, __args...);
63 30 timePerElement = ellapsedTimeCy/((double)nbElement);
64 30 timeErrorPerElement = ellapsedTimeErrorCy/((double)nbElement);
65 30 }
66
67 ///Do the micro benchmarking of a given function and gives performance results in cy and print the result
68 /** @param testName : name of the performance test
69 * @param nbTestPerf : number of performance test
70 * @param nbCallPerTest : number of calls per performance test
71 * @param nbElement : number of element treated by the function __f
72 * @param __f : function to be called and benchmarked
73 * @param __args : parameter of the function to be benchmarked
74 */
75 template<typename _Callable, typename... _Args>
76 30 void micro_benchmarkRdtscPrint(const std::string & testName, size_t nbTestPerf, size_t nbCallPerTest, size_t nbElement, _Callable&& __f, _Args&&... __args){
77 30 double ellapsedTimeCy(0.0), ellapsedTimeErrorCy(0.0), timePerElement(0.0), timeErrorPerElement(0.0);
78
1/1
✓ Branch 0 (2→3) taken 30 times.
30 micro_benchmarkRdtsc(ellapsedTimeCy, ellapsedTimeErrorCy, timePerElement, timeErrorPerElement, nbTestPerf, nbCallPerTest, nbElement, __f, __args...);
79
80
12/12
✓ Branch 0 (3→4) taken 30 times.
✓ Branch 2 (4→5) taken 30 times.
✓ Branch 4 (5→6) taken 30 times.
✓ Branch 6 (6→7) taken 30 times.
✓ Branch 8 (7→8) taken 30 times.
✓ Branch 10 (8→9) taken 30 times.
✓ Branch 12 (9→10) taken 30 times.
✓ Branch 14 (10→11) taken 30 times.
✓ Branch 16 (11→12) taken 30 times.
✓ Branch 18 (12→13) taken 30 times.
✓ Branch 20 (13→14) taken 30 times.
✓ Branch 22 (14→15) taken 30 times.
30 std::cout << testName << " : nbElement = "<<nbElement<<", timePerElement = " << timePerElement << " cy/el ± "<<timeErrorPerElement<<", elapsedTime = " << ellapsedTimeCy << " cy ± "<<ellapsedTimeErrorCy << std::endl;
81
10/10
✓ Branch 0 (15→16) taken 30 times.
✓ Branch 2 (16→17) taken 30 times.
✓ Branch 4 (17→18) taken 30 times.
✓ Branch 6 (18→19) taken 30 times.
✓ Branch 8 (19→20) taken 30 times.
✓ Branch 10 (20→21) taken 30 times.
✓ Branch 12 (21→22) taken 30 times.
✓ Branch 14 (22→23) taken 30 times.
✓ Branch 16 (23→24) taken 30 times.
✓ Branch 18 (24→25) taken 30 times.
30 std::cerr << nbElement << "\t" << timePerElement << "\t" << ellapsedTimeCy << "\t" << timeErrorPerElement << "\t" << ellapsedTimeErrorCy << std::endl;
82 30 }
83
84
85 #endif
86