-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathfunctions_benchmark.c
163 lines (142 loc) · 3.64 KB
/
functions_benchmark.c
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
156
157
158
159
160
161
162
/* This file is public domain. Author: Fredrik Johansson. */
#include "flint/profiler.h"
#include "arb.h"
#include "arb_hypgeom.h"
#include "acb.h"
#include "acb_modular.h"
#include "partitions.h"
#include "bernoulli.h"
#define TIMEIT_ONCE_STOP_VALUES(tcpu, twall) \
} while (0); \
timeit_stop(__timer); \
(tcpu) = __timer->cpu*0.001; \
(twall) = __timer->wall*0.001; \
} while (0);
void doit(arb_t res, const arb_t x, slong n, int function, slong prec)
{
if (function == 0)
arb_const_pi(res, prec);
else if (function == 1)
arb_const_euler(res, prec);
else if (function == 2)
arb_exp(res, x, prec);
else if (function == 3)
arb_log(res, x, prec);
else if (function == 4)
arb_sin(res, x, prec);
else if (function == 5)
arb_atan(res, x, prec);
else if (function == 6)
arb_hypgeom_erf(res, x, prec);
else if (function == 7)
arb_gamma(res, x, prec);
else if (function == 8)
arb_zeta(res, x, prec);
else if (function == 9)
{
acb_t t;
acb_init(t);
arb_set(acb_imagref(t), x);
acb_modular_eta(t, t, prec);
acb_clear(t);
}
else if (function == 10)
{
fmpq_t t;
fmpq_init(t);
bernoulli_fmpq_ui(t, n);
fmpq_clear(t);
}
else if (function == 11)
{
fmpz_t t;
fmpz_init(t);
fmpz_set_ui(t, n);
fmpz_mul(t, t, t);
partitions_fmpz_fmpz(t, t, 0);
fmpz_clear(t);
}
}
char * description[] = {
"const_pi, n digits",
"const_euler, n digits",
"exp(x), n digits",
"log(x), n digits",
"sin(x), n digits",
"atan(x), n digits",
"erf(x), n digits",
"gamma(x), n digits",
"zeta(x), n digits",
"eta(ix), n digits",
"bernoulli(n)",
"partitions(n^2)",
};
slong limit[] = {
1e8,
1e7,
1e7,
1e7,
1e7,
1e7,
1e6,
1e5,
1e4,
1e6,
1e6,
1e7,
};
int main()
{
arb_t x, y, res;
slong n, prec;
int function;
double tcpu, twall;
arb_init(x);
arb_init(y);
arb_init(res);
for (function = 0; function <= 11; function++)
{
printf("\n%s\n", description[function]);
printf("%12s%24s%24s\n", "", "threads = 1 ", "threads = 8 ");
printf("%12s%12s%12s%12s%12s\n", "n", "first", "repeat", "first", "repeat");
for (n = 10; n <= limit[function]; n *= 10)
{
prec = n * 3.323 + 1;
flint_printf("%12wd", n);
fflush(stdout);
arb_sqrt_ui(x, 2, prec);
arb_sub_ui(x, x, 1, prec);
flint_set_num_threads(1);
flint_cleanup();
TIMEIT_ONCE_START
doit(res, x, n, function, prec);
TIMEIT_ONCE_STOP_VALUES(tcpu, twall);
printf("%12.3g", twall);
fflush(stdout);
TIMEIT_START
doit(res, x, n, function, prec);
TIMEIT_STOP_VALUES(tcpu, twall);
printf("%12.3g", twall);
fflush(stdout);
flint_set_num_threads(8);
flint_cleanup();
TIMEIT_ONCE_START
doit(res, x, n, function, prec);
TIMEIT_ONCE_STOP_VALUES(tcpu, twall);
printf("%12.3g", twall);
fflush(stdout);
TIMEIT_START
doit(res, x, n, function, prec);
TIMEIT_STOP_VALUES(tcpu, twall);
printf("%12.3g", twall);
fflush(stdout);
tcpu = tcpu; /* unused */
printf("\n");
}
}
arb_clear(x);
arb_clear(y);
arb_clear(res);
flint_cleanup_master();
return 0;
}