ROOT
v6-26
Reference Guide
Loading...
Searching...
No Matches
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
9
static
const
int
N
= 1000000000;
// 10^9, i.e. per call is in nanoseconds
10
11
int
cpp_loop_offset
() {
12
int
i = 0;
13
for
( ; i <
N
; ++i)
14
;
15
return
i;
16
}
17
18
//- group: empty-free --------------------------------------------------------
19
void
cpp_free_empty_call
() {
20
for
(
int
i=0; i <
N
; ++i)
21
empty_call
();
22
}
23
24
//- group: empty-inst --------------------------------------------------------
25
void
cpp_inst_empty_call
() {
26
EmptyCall
e
;
27
for
(
int
i=0; i <
N
; ++i)
28
e
.
empty_call
();
29
}
30
31
32
//- group: builtin-args-inst -------------------------------------------------
33
void
cpp_inst_pass_int
() {
34
TakeAValue
t;
35
for
(
int
i=0; i <
N
; ++i)
36
t.
pass_int
(i);
37
}
38
39
40
//- group: do-work -----------------------------------------------------------
41
void
cpp_inst_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 -------------------------------------------------------
49
void
cpp_inst_overload
() {
50
OverloadedCall
o;
51
for
(
int
i=0; i <
N
; ++i)
52
o.
add_it
((
float
)i);
53
}
54
55
56
//----------------------------------------------------------------------------
57
void
run_bench
(
void
(*cpp_bench)(),
const
char
* label) {
58
clock_t
t1
= clock();
59
cpp_loop_offset
();
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
68
int
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
}
d
#define d(i)
Definition
RSha256.hxx:102
e
#define e(i)
Definition
RSha256.hxx:103
DoWork
Definition
functioncalls.h:36
DoWork::do_work
double do_work(double)
Definition
functioncalls.cxx:54
EmptyCall
Definition
functioncalls.h:8
EmptyCall::empty_call
void empty_call()
Definition
functioncalls.cxx:12
OverloadedCall
Definition
functioncalls.h:43
OverloadedCall::add_it
double add_it(int a, int b)
Definition
functioncalls.cxx:60
TakeAValue
Definition
functioncalls.h:22
TakeAValue::pass_int
int pass_int(int)
Definition
functioncalls.cxx:44
empty_call
void empty_call()
Definition
functioncalls.cxx:8
functioncalls.h
cpp_inst_pass_int
void cpp_inst_pass_int()
Definition
functioncalls_main.cxx:33
cpp_inst_empty_call
void cpp_inst_empty_call()
Definition
functioncalls_main.cxx:25
cpp_loop_offset
int cpp_loop_offset()
Definition
functioncalls_main.cxx:11
cpp_inst_do_work
void cpp_inst_do_work()
Definition
functioncalls_main.cxx:41
cpp_inst_overload
void cpp_inst_overload()
Definition
functioncalls_main.cxx:49
run_bench
void run_bench(void(*cpp_bench)(), const char *label)
Definition
functioncalls_main.cxx:57
N
static const int N
Definition
functioncalls_main.cxx:9
main
int main()
Definition
functioncalls_main.cxx:68
cpp_free_empty_call
void cpp_free_empty_call()
Definition
functioncalls_main.cxx:19
t1
auto * t1
Definition
textangle.C:20
bindings
pyroot
cppyy
cppyy
bench
functioncalls_main.cxx
ROOT v6-26 - Reference Guide Generated on Mon Sep 11 2023 21:02:09 (GVA Time) using Doxygen 1.9.8