Logo ROOT  
Reference Guide
functioncalls_main.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3#include <time.h>
4#include <unistd.h>
5
6#include "functioncalls.h"
7
8
9static const int N = 1000000000; // 10^9, i.e. per call is in nanoseconds
10
12 int i = 0;
13 for ( ; i < N; ++i)
14 ;
15 return i;
16}
17
18//- group: empty-free --------------------------------------------------------
20 for (int i=0; i < N; ++i)
21 empty_call();
22}
23
24//- group: empty-inst --------------------------------------------------------
27 for (int i=0; i < N; ++i)
28 e.empty_call();
29}
30
31
32//- group: builtin-args-inst -------------------------------------------------
34 TakeAValue t;
35 for (int i=0; i < N; ++i)
36 t.pass_int(i);
37}
38
39
40//- group: do-work -----------------------------------------------------------
42 DoWork d;
43 for (int i=0; i < N; ++i)
44 d.do_work(i);
45}
46
47
48//- group: do-overload -------------------------------------------------------
51 for (int i=0; i < N; ++i)
52 o.add_it((float)i);
53}
54
55
56//----------------------------------------------------------------------------
57void run_bench(void (*cpp_bench)(), const char* label) {
58 clock_t t1 = clock();
60 clock_t t2 = clock();
61 cpp_bench();
62 clock_t t3 = clock();
63
64 std::cout << label << ": " << std::setprecision(8)
65 << ((t3-t2) - (t2-t1))/((double)CLOCKS_PER_SEC) << " nanoseconds" << std::endl;
66}
67
68int main() {
69 run_bench(cpp_free_empty_call, "cpp_free_empty_call");
70 run_bench(cpp_inst_empty_call, "cpp_inst_empty_call");
71 run_bench(cpp_inst_pass_int, "cpp_inst_pass_int");
72 run_bench(cpp_inst_do_work, "cpp_do_work");
73 run_bench(cpp_inst_overload, "cpp_inst_overload");
74 return 0;
75}
#define d(i)
Definition: RSha256.hxx:102
#define e(i)
Definition: RSha256.hxx:103
double add_it(int a, int b)
int pass_int(int)
void empty_call()
void cpp_inst_pass_int()
void cpp_inst_empty_call()
int cpp_loop_offset()
void cpp_inst_do_work()
void cpp_inst_overload()
void run_bench(void(*cpp_bench)(), const char *label)
static const int N
int main()
void cpp_free_empty_call()
auto * t1
Definition: textangle.C:20