Logo ROOT  
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
10static 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 --------------------------------------------------------
22 for (auto i: global_vector)
23 global_effect += i;
24}
25
26
27//----------------------------------------------------------------------------
28void 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
39int main() {
40 run_bench(cpp_runvector, "cpp_runvector");
41 return 0;
42}
std::vector< int > global_vector
Definition runvector.cxx:3
double global_effect
Definition runvector.cxx:4
int cpp_loop_offset()
void run_bench(void(*cpp_bench)(), const char *label)
static const int N
void cpp_runvector()
int main()
auto * t1
Definition textangle.C:20