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 17package benchmarks.regression; 18 19import com.google.caliper.Param; 20import com.google.caliper.Runner; 21import com.google.caliper.SimpleBenchmark; 22 23/** 24 * Many of these tests are bogus in that the cost will vary wildly depending on inputs. 25 * For _my_ current purposes, that's okay. But beware! 26 */ 27public class StrictMathBenchmark extends SimpleBenchmark { 28 private final double d = 1.2; 29 private final float f = 1.2f; 30 private final int i = 1; 31 private final long l = 1L; 32 33 public void timeAbsD(int reps) { 34 for (int rep = 0; rep < reps; ++rep) { 35 StrictMath.abs(d); 36 } 37 } 38 39 public void timeAbsF(int reps) { 40 for (int rep = 0; rep < reps; ++rep) { 41 StrictMath.abs(f); 42 } 43 } 44 45 public void timeAbsI(int reps) { 46 for (int rep = 0; rep < reps; ++rep) { 47 StrictMath.abs(i); 48 } 49 } 50 51 public void timeAbsL(int reps) { 52 for (int rep = 0; rep < reps; ++rep) { 53 StrictMath.abs(l); 54 } 55 } 56 57 public void timeAcos(int reps) { 58 for (int rep = 0; rep < reps; ++rep) { 59 StrictMath.acos(d); 60 } 61 } 62 63 public void timeAsin(int reps) { 64 for (int rep = 0; rep < reps; ++rep) { 65 StrictMath.asin(d); 66 } 67 } 68 69 public void timeAtan(int reps) { 70 for (int rep = 0; rep < reps; ++rep) { 71 StrictMath.atan(d); 72 } 73 } 74 75 public void timeAtan2(int reps) { 76 for (int rep = 0; rep < reps; ++rep) { 77 StrictMath.atan2(3, 4); 78 } 79 } 80 81 public void timeCbrt(int reps) { 82 for (int rep = 0; rep < reps; ++rep) { 83 StrictMath.cbrt(d); 84 } 85 } 86 87 public void timeCeil(int reps) { 88 for (int rep = 0; rep < reps; ++rep) { 89 StrictMath.ceil(d); 90 } 91 } 92 93 public void timeCopySignD(int reps) { 94 for (int rep = 0; rep < reps; ++rep) { 95 StrictMath.copySign(d, d); 96 } 97 } 98 99 public void timeCopySignF(int reps) { 100 for (int rep = 0; rep < reps; ++rep) { 101 StrictMath.copySign(f, f); 102 } 103 } 104 105 public void timeCos(int reps) { 106 for (int rep = 0; rep < reps; ++rep) { 107 StrictMath.cos(d); 108 } 109 } 110 111 public void timeCosh(int reps) { 112 for (int rep = 0; rep < reps; ++rep) { 113 StrictMath.cosh(d); 114 } 115 } 116 117 public void timeExp(int reps) { 118 for (int rep = 0; rep < reps; ++rep) { 119 StrictMath.exp(d); 120 } 121 } 122 123 public void timeExpm1(int reps) { 124 for (int rep = 0; rep < reps; ++rep) { 125 StrictMath.expm1(d); 126 } 127 } 128 129 public void timeFloor(int reps) { 130 for (int rep = 0; rep < reps; ++rep) { 131 StrictMath.floor(d); 132 } 133 } 134 135 public void timeGetExponentD(int reps) { 136 for (int rep = 0; rep < reps; ++rep) { 137 StrictMath.getExponent(d); 138 } 139 } 140 141 public void timeGetExponentF(int reps) { 142 for (int rep = 0; rep < reps; ++rep) { 143 StrictMath.getExponent(f); 144 } 145 } 146 147 public void timeHypot(int reps) { 148 for (int rep = 0; rep < reps; ++rep) { 149 StrictMath.hypot(d, d); 150 } 151 } 152 153 public void timeIEEEremainder(int reps) { 154 for (int rep = 0; rep < reps; ++rep) { 155 StrictMath.IEEEremainder(d, d); 156 } 157 } 158 159 public void timeLog(int reps) { 160 for (int rep = 0; rep < reps; ++rep) { 161 StrictMath.log(d); 162 } 163 } 164 165 public void timeLog10(int reps) { 166 for (int rep = 0; rep < reps; ++rep) { 167 StrictMath.log10(d); 168 } 169 } 170 171 public void timeLog1p(int reps) { 172 for (int rep = 0; rep < reps; ++rep) { 173 StrictMath.log1p(d); 174 } 175 } 176 177 public void timeMaxD(int reps) { 178 for (int rep = 0; rep < reps; ++rep) { 179 StrictMath.max(d, d); 180 } 181 } 182 183 public void timeMaxF(int reps) { 184 for (int rep = 0; rep < reps; ++rep) { 185 StrictMath.max(f, f); 186 } 187 } 188 189 public void timeMaxI(int reps) { 190 for (int rep = 0; rep < reps; ++rep) { 191 StrictMath.max(i, i); 192 } 193 } 194 195 public void timeMaxL(int reps) { 196 for (int rep = 0; rep < reps; ++rep) { 197 StrictMath.max(l, l); 198 } 199 } 200 201 public void timeMinD(int reps) { 202 for (int rep = 0; rep < reps; ++rep) { 203 StrictMath.min(d, d); 204 } 205 } 206 207 public void timeMinF(int reps) { 208 for (int rep = 0; rep < reps; ++rep) { 209 StrictMath.min(f, f); 210 } 211 } 212 213 public void timeMinI(int reps) { 214 for (int rep = 0; rep < reps; ++rep) { 215 StrictMath.min(i, i); 216 } 217 } 218 219 public void timeMinL(int reps) { 220 for (int rep = 0; rep < reps; ++rep) { 221 StrictMath.min(l, l); 222 } 223 } 224 225 public void timeNextAfterD(int reps) { 226 for (int rep = 0; rep < reps; ++rep) { 227 StrictMath.nextAfter(d, d); 228 } 229 } 230 231 public void timeNextAfterF(int reps) { 232 for (int rep = 0; rep < reps; ++rep) { 233 StrictMath.nextAfter(f, f); 234 } 235 } 236 237 public void timeNextUpD(int reps) { 238 for (int rep = 0; rep < reps; ++rep) { 239 StrictMath.nextUp(d); 240 } 241 } 242 243 public void timeNextUpF(int reps) { 244 for (int rep = 0; rep < reps; ++rep) { 245 StrictMath.nextUp(f); 246 } 247 } 248 249 public void timePow(int reps) { 250 for (int rep = 0; rep < reps; ++rep) { 251 StrictMath.pow(d, d); 252 } 253 } 254 255 public void timeRandom(int reps) { 256 for (int rep = 0; rep < reps; ++rep) { 257 StrictMath.random(); 258 } 259 } 260 261 public void timeRint(int reps) { 262 for (int rep = 0; rep < reps; ++rep) { 263 StrictMath.rint(d); 264 } 265 } 266 267 public void timeRoundD(int reps) { 268 for (int rep = 0; rep < reps; ++rep) { 269 StrictMath.round(d); 270 } 271 } 272 273 public void timeRoundF(int reps) { 274 for (int rep = 0; rep < reps; ++rep) { 275 StrictMath.round(f); 276 } 277 } 278 279 public void timeScalbD(int reps) { 280 for (int rep = 0; rep < reps; ++rep) { 281 StrictMath.scalb(d, 5); 282 } 283 } 284 285 public void timeScalbF(int reps) { 286 for (int rep = 0; rep < reps; ++rep) { 287 StrictMath.scalb(f, 5); 288 } 289 } 290 291 public void timeSignumD(int reps) { 292 for (int rep = 0; rep < reps; ++rep) { 293 StrictMath.signum(d); 294 } 295 } 296 297 public void timeSignumF(int reps) { 298 for (int rep = 0; rep < reps; ++rep) { 299 StrictMath.signum(f); 300 } 301 } 302 303 public void timeSin(int reps) { 304 for (int rep = 0; rep < reps; ++rep) { 305 StrictMath.sin(d); 306 } 307 } 308 309 public void timeSinh(int reps) { 310 for (int rep = 0; rep < reps; ++rep) { 311 StrictMath.sinh(d); 312 } 313 } 314 315 public void timeSqrt(int reps) { 316 for (int rep = 0; rep < reps; ++rep) { 317 StrictMath.sqrt(d); 318 } 319 } 320 321 public void timeTan(int reps) { 322 for (int rep = 0; rep < reps; ++rep) { 323 StrictMath.tan(d); 324 } 325 } 326 327 public void timeTanh(int reps) { 328 for (int rep = 0; rep < reps; ++rep) { 329 StrictMath.tanh(d); 330 } 331 } 332 333 public void timeToDegrees(int reps) { 334 for (int rep = 0; rep < reps; ++rep) { 335 StrictMath.toDegrees(d); 336 } 337 } 338 339 public void timeToRadians(int reps) { 340 for (int rep = 0; rep < reps; ++rep) { 341 StrictMath.toRadians(d); 342 } 343 } 344 345 public void timeUlpD(int reps) { 346 for (int rep = 0; rep < reps; ++rep) { 347 StrictMath.ulp(d); 348 } 349 } 350 351 public void timeUlpF(int reps) { 352 for (int rep = 0; rep < reps; ++rep) { 353 StrictMath.ulp(f); 354 } 355 } 356} 357