Dash Core
0.12.2.1
P2P Digital Currency
bench.h
Go to the documentation of this file.
1
/**********************************************************************
2
* Copyright (c) 2014 Pieter Wuille *
3
* Distributed under the MIT software license, see the accompanying *
4
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
5
**********************************************************************/
6
7
#ifndef _SECP256K1_BENCH_H_
8
#define _SECP256K1_BENCH_H_
9
10
#include <stdio.h>
11
#include <math.h>
12
#include "sys/time.h"
13
14
static
double
gettimedouble
(
void
) {
15
struct
timeval tv;
16
gettimeofday(&tv, NULL);
17
return
tv.tv_usec * 0.000001 + tv.tv_sec;
18
}
19
20
void
print_number
(
double
x) {
21
double
y = x;
22
int
c = 0;
23
if
(y < 0.0) {
24
y = -y;
25
}
26
while
(y < 100.0) {
27
y *= 10.0;
28
c++;
29
}
30
printf(
"%.*f"
, c, x);
31
}
32
33
void
run_benchmark
(
char
*
name
,
void
(*
benchmark
)(
void
*),
void
(*
setup
)(
void
*),
void
(*teardown)(
void
*),
void
*
data
,
int
count
,
int
iter) {
34
int
i;
35
double
min = HUGE_VAL;
36
double
sum
= 0.0;
37
double
max = 0.0;
38
for
(i = 0; i <
count
; i++) {
39
double
begin, total;
40
if
(
setup
!= NULL) {
41
setup
(
data
);
42
}
43
begin =
gettimedouble
();
44
benchmark
(
data
);
45
total =
gettimedouble
() - begin;
46
if
(teardown != NULL) {
47
teardown(
data
);
48
}
49
if
(total < min) {
50
min = total;
51
}
52
if
(total > max) {
53
max = total;
54
}
55
sum
+= total;
56
}
57
printf(
"%s: min "
,
name
);
58
print_number
(min * 1000000.0 / iter);
59
printf(
"us / avg "
);
60
print_number
((
sum
/
count
) * 1000000.0 / iter);
61
printf(
"us / max "
);
62
print_number
(max * 1000000.0 / iter);
63
printf(
"us\n"
);
64
}
65
66
#endif
setup
Definition:
setup.py:1
sum
volatile double sum
Definition:
Examples.cpp:23
gen_base58_test_vectors.data
data
Definition:
gen_base58_test_vectors.py:123
run_benchmark
void run_benchmark(char *name, void(*benchmark)(void *), void(*setup)(void *), void(*teardown)(void *), void *data, int count, int iter)
Definition:
bench.h:33
print_number
void print_number(double x)
Definition:
bench.h:20
name
const char * name
Definition:
rest.cpp:37
benchmark
Definition:
bench.h:37
count
static int count
Definition:
tests.c:41
gettimedouble
static double gettimedouble(void)
Definition:
bench.h:14
src
secp256k1
src
bench.h
Generated on Thu Dec 14 2017 13:15:02 for Dash Core by
1.8.14