1 /* 2 * Copyright (C) 2010 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package benchmarks.regression; 18 19 /** 20 * Many of these tests are bogus in that the cost will vary wildly depending on inputs. 21 * For _my_ current purposes, that's okay. But beware! 22 */ 23 public class StrictMathBenchmark { 24 private final double d = 1.2; 25 private final float f = 1.2f; 26 private final int i = 1; 27 private final long l = 1L; 28 29 /* Values for full line coverage of ceiling function */ 30 private static final double[] CEIL_DOUBLES = new double[] { 31 3245817.2018463886, 32 1418139.083668501, 33 3.572936802189103E15, 34 -4.7828929737254625E249, 35 213596.58636369856, 36 6.891928421440976E-96, 37 -7.9318566885477E-36, 38 -1.9610339084804148E15, 39 -4.696725715628246E10, 40 3742491.296880909, 41 7.140274745333553E11 42 }; 43 44 /* Values for full line coverage of floor function */ 45 private static final double[] FLOOR_DOUBLES = new double[] { 46 7.140274745333553E11, 47 3742491.296880909, 48 -4.696725715628246E10, 49 -1.9610339084804148E15, 50 7.049948629370372E-56, 51 -7.702933170334643E-16, 52 -1.99657681810579, 53 -1.1659287182288336E236, 54 4.085518816513057E15, 55 -1500948.440658056, 56 -2.2316479921415575E7 57 }; 58 59 public void timeAbsD(int reps) { 60 for (int rep = 0; rep < reps; ++rep) { 61 StrictMath.abs(d); 62 } 63 } 64 65 public void timeAbsF(int reps) { 66 for (int rep = 0; rep < reps; ++rep) { 67 StrictMath.abs(f); 68 } 69 } 70 71 public void timeAbsI(int reps) { 72 for (int rep = 0; rep < reps; ++rep) { 73 StrictMath.abs(i); 74 } 75 } 76 77 public void timeAbsL(int reps) { 78 for (int rep = 0; rep < reps; ++rep) { 79 StrictMath.abs(l); 80 } 81 } 82 83 public void timeAcos(int reps) { 84 for (int rep = 0; rep < reps; ++rep) { 85 StrictMath.acos(d); 86 } 87 } 88 89 public void timeAsin(int reps) { 90 for (int rep = 0; rep < reps; ++rep) { 91 StrictMath.asin(d); 92 } 93 } 94 95 public void timeAtan(int reps) { 96 for (int rep = 0; rep < reps; ++rep) { 97 StrictMath.atan(d); 98 } 99 } 100 101 public void timeAtan2(int reps) { 102 for (int rep = 0; rep < reps; ++rep) { 103 StrictMath.atan2(3, 4); 104 } 105 } 106 107 public void timeCbrt(int reps) { 108 for (int rep = 0; rep < reps; ++rep) { 109 StrictMath.cbrt(d); 110 } 111 } 112 113 public void timeCeilOverInterestingValues(int reps) { 114 for (int rep = 0; rep < reps; ++rep) { 115 for (int i = 0; i < CEIL_DOUBLES.length; ++i) { 116 StrictMath.ceil(CEIL_DOUBLES[i]); 117 } 118 } 119 } 120 121 public void timeCopySignD(int reps) { 122 for (int rep = 0; rep < reps; ++rep) { 123 StrictMath.copySign(d, d); 124 } 125 } 126 127 public void timeCopySignF(int reps) { 128 for (int rep = 0; rep < reps; ++rep) { 129 StrictMath.copySign(f, f); 130 } 131 } 132 133 public void timeCos(int reps) { 134 for (int rep = 0; rep < reps; ++rep) { 135 StrictMath.cos(d); 136 } 137 } 138 139 public void timeCosh(int reps) { 140 for (int rep = 0; rep < reps; ++rep) { 141 StrictMath.cosh(d); 142 } 143 } 144 145 public void timeExp(int reps) { 146 for (int rep = 0; rep < reps; ++rep) { 147 StrictMath.exp(d); 148 } 149 } 150 151 public void timeExpm1(int reps) { 152 for (int rep = 0; rep < reps; ++rep) { 153 StrictMath.expm1(d); 154 } 155 } 156 157 public void timeFloorOverInterestingValues(int reps) { 158 for (int rep = 0; rep < reps; ++rep) { 159 for (int i = 0; i < FLOOR_DOUBLES.length; ++i) { 160 StrictMath.floor(FLOOR_DOUBLES[i]); 161 } 162 } 163 } 164 165 public void timeGetExponentD(int reps) { 166 for (int rep = 0; rep < reps; ++rep) { 167 StrictMath.getExponent(d); 168 } 169 } 170 171 public void timeGetExponentF(int reps) { 172 for (int rep = 0; rep < reps; ++rep) { 173 StrictMath.getExponent(f); 174 } 175 } 176 177 public void timeHypot(int reps) { 178 for (int rep = 0; rep < reps; ++rep) { 179 StrictMath.hypot(d, d); 180 } 181 } 182 183 public void timeIEEEremainder(int reps) { 184 for (int rep = 0; rep < reps; ++rep) { 185 StrictMath.IEEEremainder(d, d); 186 } 187 } 188 189 public void timeLog(int reps) { 190 for (int rep = 0; rep < reps; ++rep) { 191 StrictMath.log(d); 192 } 193 } 194 195 public void timeLog10(int reps) { 196 for (int rep = 0; rep < reps; ++rep) { 197 StrictMath.log10(d); 198 } 199 } 200 201 public void timeLog1p(int reps) { 202 for (int rep = 0; rep < reps; ++rep) { 203 StrictMath.log1p(d); 204 } 205 } 206 207 public void timeMaxD(int reps) { 208 for (int rep = 0; rep < reps; ++rep) { 209 StrictMath.max(d, d); 210 } 211 } 212 213 public void timeMaxF(int reps) { 214 for (int rep = 0; rep < reps; ++rep) { 215 StrictMath.max(f, f); 216 } 217 } 218 219 public void timeMaxI(int reps) { 220 for (int rep = 0; rep < reps; ++rep) { 221 StrictMath.max(i, i); 222 } 223 } 224 225 public void timeMaxL(int reps) { 226 for (int rep = 0; rep < reps; ++rep) { 227 StrictMath.max(l, l); 228 } 229 } 230 231 public void timeMinD(int reps) { 232 for (int rep = 0; rep < reps; ++rep) { 233 StrictMath.min(d, d); 234 } 235 } 236 237 public void timeMinF(int reps) { 238 for (int rep = 0; rep < reps; ++rep) { 239 StrictMath.min(f, f); 240 } 241 } 242 243 public void timeMinI(int reps) { 244 for (int rep = 0; rep < reps; ++rep) { 245 StrictMath.min(i, i); 246 } 247 } 248 249 public void timeMinL(int reps) { 250 for (int rep = 0; rep < reps; ++rep) { 251 StrictMath.min(l, l); 252 } 253 } 254 255 public void timeNextAfterD(int reps) { 256 for (int rep = 0; rep < reps; ++rep) { 257 StrictMath.nextAfter(d, d); 258 } 259 } 260 261 public void timeNextAfterF(int reps) { 262 for (int rep = 0; rep < reps; ++rep) { 263 StrictMath.nextAfter(f, f); 264 } 265 } 266 267 public void timeNextUpD(int reps) { 268 for (int rep = 0; rep < reps; ++rep) { 269 StrictMath.nextUp(d); 270 } 271 } 272 273 public void timeNextUpF(int reps) { 274 for (int rep = 0; rep < reps; ++rep) { 275 StrictMath.nextUp(f); 276 } 277 } 278 279 public void timePow(int reps) { 280 for (int rep = 0; rep < reps; ++rep) { 281 StrictMath.pow(d, d); 282 } 283 } 284 285 public void timeRandom(int reps) { 286 for (int rep = 0; rep < reps; ++rep) { 287 StrictMath.random(); 288 } 289 } 290 291 public void timeRint(int reps) { 292 for (int rep = 0; rep < reps; ++rep) { 293 StrictMath.rint(d); 294 } 295 } 296 297 public void timeRoundD(int reps) { 298 for (int rep = 0; rep < reps; ++rep) { 299 StrictMath.round(d); 300 } 301 } 302 303 public void timeRoundF(int reps) { 304 for (int rep = 0; rep < reps; ++rep) { 305 StrictMath.round(f); 306 } 307 } 308 309 public void timeScalbD(int reps) { 310 for (int rep = 0; rep < reps; ++rep) { 311 StrictMath.scalb(d, 5); 312 } 313 } 314 315 public void timeScalbF(int reps) { 316 for (int rep = 0; rep < reps; ++rep) { 317 StrictMath.scalb(f, 5); 318 } 319 } 320 321 public void timeSignumD(int reps) { 322 for (int rep = 0; rep < reps; ++rep) { 323 StrictMath.signum(d); 324 } 325 } 326 327 public void timeSignumF(int reps) { 328 for (int rep = 0; rep < reps; ++rep) { 329 StrictMath.signum(f); 330 } 331 } 332 333 public void timeSin(int reps) { 334 for (int rep = 0; rep < reps; ++rep) { 335 StrictMath.sin(d); 336 } 337 } 338 339 public void timeSinh(int reps) { 340 for (int rep = 0; rep < reps; ++rep) { 341 StrictMath.sinh(d); 342 } 343 } 344 345 public void timeSqrt(int reps) { 346 for (int rep = 0; rep < reps; ++rep) { 347 StrictMath.sqrt(d); 348 } 349 } 350 351 public void timeTan(int reps) { 352 for (int rep = 0; rep < reps; ++rep) { 353 StrictMath.tan(d); 354 } 355 } 356 357 public void timeTanh(int reps) { 358 for (int rep = 0; rep < reps; ++rep) { 359 StrictMath.tanh(d); 360 } 361 } 362 363 public void timeToDegrees(int reps) { 364 for (int rep = 0; rep < reps; ++rep) { 365 StrictMath.toDegrees(d); 366 } 367 } 368 369 public void timeToRadians(int reps) { 370 for (int rep = 0; rep < reps; ++rep) { 371 StrictMath.toRadians(d); 372 } 373 } 374 375 public void timeUlpD(int reps) { 376 for (int rep = 0; rep < reps; ++rep) { 377 StrictMath.ulp(d); 378 } 379 } 380 381 public void timeUlpF(int reps) { 382 for (int rep = 0; rep < reps; ++rep) { 383 StrictMath.ulp(f); 384 } 385 } 386 } 387