Logo ROOT  
Reference Guide
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 
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();
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 }
runvector.h
global_effect
double global_effect
Definition: runvector.cxx:4
cpp_runvector
void cpp_runvector()
Definition: runvector_main.cxx:21
global_vector
std::vector< int > global_vector
Definition: runvector.cxx:3
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
main
int main()
Definition: runvector_main.cxx:39
t1
auto * t1
Definition: textangle.C:20
N
static const int N
Definition: runvector_main.cxx:10