summaryrefslogtreecommitdiffstats
path: root/benchmarks/regression/StrictMathBenchmark.java
blob: 44c030a41b2ae9903ab78d2a2b3405dbf8061a63 (plain)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/*
 * Copyright (C) 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package benchmarks.regression;

import com.google.caliper.Param;
import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark;

/**
 * Many of these tests are bogus in that the cost will vary wildly depending on inputs.
 * For _my_ current purposes, that's okay. But beware!
 */
public class StrictMathBenchmark extends SimpleBenchmark {
    private final double d = 1.2;
    private final float f = 1.2f;
    private final int i = 1;
    private final long l = 1L;

    public void timeAbsD(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.abs(d);
        }
    }

    public void timeAbsF(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.abs(f);
        }
    }

    public void timeAbsI(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.abs(i);
        }
    }

    public void timeAbsL(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.abs(l);
        }
    }

    public void timeAcos(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.acos(d);
        }
    }

    public void timeAsin(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.asin(d);
        }
    }

    public void timeAtan(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.atan(d);
        }
    }

    public void timeAtan2(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.atan2(3, 4);
        }
    }

    public void timeCbrt(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.cbrt(d);
        }
    }

    public void timeCeil(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.ceil(d);
        }
    }

    public void timeCopySignD(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.copySign(d, d);
        }
    }

    public void timeCopySignF(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.copySign(f, f);
        }
    }

    public void timeCos(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.cos(d);
        }
    }

    public void timeCosh(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.cosh(d);
        }
    }

    public void timeExp(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.exp(d);
        }
    }

    public void timeExpm1(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.expm1(d);
        }
    }

    public void timeFloor(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.floor(d);
        }
    }

    public void timeGetExponentD(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.getExponent(d);
        }
    }

    public void timeGetExponentF(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.getExponent(f);
        }
    }

    public void timeHypot(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.hypot(d, d);
        }
    }

    public void timeIEEEremainder(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.IEEEremainder(d, d);
        }
    }

    public void timeLog(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.log(d);
        }
    }

    public void timeLog10(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.log10(d);
        }
    }

    public void timeLog1p(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.log1p(d);
        }
    }

    public void timeMaxD(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.max(d, d);
        }
    }

    public void timeMaxF(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.max(f, f);
        }
    }

    public void timeMaxI(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.max(i, i);
        }
    }

    public void timeMaxL(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.max(l, l);
        }
    }

    public void timeMinD(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.min(d, d);
        }
    }

    public void timeMinF(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.min(f, f);
        }
    }

    public void timeMinI(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.min(i, i);
        }
    }

    public void timeMinL(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.min(l, l);
        }
    }

    public void timeNextAfterD(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.nextAfter(d, d);
        }
    }

    public void timeNextAfterF(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.nextAfter(f, f);
        }
    }

    public void timeNextUpD(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.nextUp(d);
        }
    }

    public void timeNextUpF(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.nextUp(f);
        }
    }

    public void timePow(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.pow(d, d);
        }
    }

    public void timeRandom(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.random();
        }
    }

    public void timeRint(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.rint(d);
        }
    }

    public void timeRoundD(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.round(d);
        }
    }

    public void timeRoundF(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.round(f);
        }
    }

    public void timeScalbD(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.scalb(d, 5);
        }
    }

    public void timeScalbF(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.scalb(f, 5);
        }
    }

    public void timeSignumD(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.signum(d);
        }
    }

    public void timeSignumF(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.signum(f);
        }
    }

    public void timeSin(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.sin(d);
        }
    }

    public void timeSinh(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.sinh(d);
        }
    }

    public void timeSqrt(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.sqrt(d);
        }
    }

    public void timeTan(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.tan(d);
        }
    }

    public void timeTanh(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.tanh(d);
        }
    }

    public void timeToDegrees(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.toDegrees(d);
        }
    }

    public void timeToRadians(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.toRadians(d);
        }
    }

    public void timeUlpD(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.ulp(d);
        }
    }

    public void timeUlpF(int reps) {
        for (int rep = 0; rep < reps; ++rep) {
            StrictMath.ulp(f);
        }
    }
}