-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathop_bench.h
155 lines (136 loc) · 4.43 KB
/
op_bench.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* OpenPairing is an implementation of a bilinear pairing over OpenSSL
* Copyright (C) 2015 OpenPairing Authors
*
* This file is part of OpenPairing. OpenPairing is legal property of its
* developers, whose names are not listed here. Please refer to the COPYRIGHT
* file for contact information.
*
* OpenPairing is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* OpenPairing is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenPairing. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file
*
* Interface of useful routines for benchmarking.
*
* @ingroup bench
*/
#ifndef OP_BENCH_H
#define OP_BENCH_H
/*============================================================================*/
/* Constant definitions */
/*============================================================================*/
/**
* Number of times to run benchmarks.
*/
#define BENCH 10
/*============================================================================*/
/* Macro definitions */
/*============================================================================*/
/**
* Runs a new benchmark once.
*
* @param[in] LABEL - the label for this benchmark.
* @param[in] FUNCTION - the function to benchmark.
*/
#define BENCH_ONCE(LABEL, FUNCTION) \
BENCH_reset(); \
printf("BENCH: " LABEL "%*c = ", (int)(32 - strlen(LABEL)), ' '); \
BENCH_before(); \
FUNCTION; \
BENCH_after(); \
BENCH_compute(1); \
BENCH_print(); \
/**
* Runs a new benchmark a small number of times.
*
* @param[in] LABEL - the label for this benchmark.
* @param[in] FUNCTION - the function to benchmark.
*/
#define BENCH_SMALL(LABEL, FUNCTION) \
BENCH_reset(); \
printf("BENCH: " LABEL "%*c = ", (int)(32 - strlen(LABEL)), ' '); \
BENCH_before(); \
for (int i = 0; i < BENCH; i++) { \
FUNCTION; \
} \
BENCH_after(); \
BENCH_compute(BENCH); \
BENCH_print(); \
/**
* Runs a new benchmark.
*
* @param[in] LABEL - the label for this benchmark.
*/
#define BENCH_BEGIN(LABEL) \
BENCH_reset(); \
printf("BENCH: " LABEL "%*c = ", (int)(32 - strlen(LABEL)), ' '); \
for (int i = 0; i < BENCH; i++) { \
/**
* Prints the mean timing of each execution in nanoseconds.
*/
#define BENCH_END \
} \
BENCH_compute(BENCH * BENCH); \
BENCH_print() \
/**
* Measures the time of one execution and adds it to the benchmark total.
*
* @param[in] FUNCTION - the function executed.
*/
#define BENCH_ADD(FUNCTION) \
FUNCTION; \
BENCH_before(); \
for (int j = 0; j < BENCH; j++) { \
FUNCTION; \
} \
BENCH_after(); \
/*============================================================================*/
/* Function prototypes */
/*============================================================================*/
/**
* Measures and prints benchmarking overhead.
*/
void BENCH_overhead(void);
/**
* Resets the benchmark data.
*
* @param[in] label - the benchmark label.
*/
void BENCH_reset(void);
/**
* Measures the time before a benchmark is executed.
*/
void BENCH_before(void);
/**
* Measures the time after a benchmark was started and adds it to the total.
*/
void BENCH_after(void);
/**
* Computes the mean elapsed time between the start and the end of a benchmark.
*
* @param benches - the number of executed benchmarks.
*/
void BENCH_compute(int benches);
/**
* Prints the last benchmark.
*/
void BENCH_print(void);
/**
* Returns the result of the last benchmark.
*
* @return the last benchmark.
*/
unsigned long long BENCH_total(void);
#endif /* !OP_BENCH_H */