ROOT
v6-26
Reference Guide
Loading...
Searching...
No Matches
runvector_main.cxx
Go to the documentation of this file.
1
#include <iostream>
2
#include <iomanip>
3
#include <vector>
4
#include <time.h>
5
#include <unistd.h>
6
7
#include "
runvector.h
"
8
9
10
static
const
int
N
= 100000000;
// 10^8, i.e. per call is in 10 nanoseconds
11
12
int
cpp_loop_offset
() {
13
int
i = 0;
14
for
( ; i <
N
; ++i)
15
;
16
return
i;
17
}
18
19
20
//- group: stl-vector --------------------------------------------------------
21
void
cpp_runvector
() {
22
for
(
auto
i:
global_vector
)
23
global_effect
+= i;
24
}
25
26
27
//----------------------------------------------------------------------------
28
void
run_bench
(
void
(*cpp_bench)(),
const
char
* label) {
29
clock_t
t1
= clock();
30
cpp_loop_offset
();
31
clock_t t2 = clock();
32
cpp_bench();
33
clock_t t3 = clock();
34
35
std::cout << label <<
": "
<< std::setprecision(8)
36
<< 10.*((t3-t2) - (t2-
t1
))/((
double
)CLOCKS_PER_SEC) <<
" nanoseconds"
<< std::endl;
37
}
38
39
int
main
() {
40
run_bench
(
cpp_runvector
,
"cpp_runvector"
);
41
return
0;
42
}
global_vector
std::vector< int > global_vector
Definition
runvector.cxx:3
global_effect
double global_effect
Definition
runvector.cxx:4
runvector.h
cpp_loop_offset
int cpp_loop_offset()
Definition
runvector_main.cxx:12
run_bench
void run_bench(void(*cpp_bench)(), const char *label)
Definition
runvector_main.cxx:28
N
static const int N
Definition
runvector_main.cxx:10
cpp_runvector
void cpp_runvector()
Definition
runvector_main.cxx:21
main
int main()
Definition
runvector_main.cxx:39
t1
auto * t1
Definition
textangle.C:20
bindings
pyroot
cppyy
cppyy
bench
runvector_main.cxx
ROOT v6-26 - Reference Guide Generated on Mon Sep 11 2023 21:02:09 (GVA Time) using Doxygen 1.9.8