aboutsummaryrefslogtreecommitdiffstats
path: root/guava-tests/benchmark/com/google/common/math
diff options
context:
space:
mode:
Diffstat (limited to 'guava-tests/benchmark/com/google/common/math')
-rw-r--r--guava-tests/benchmark/com/google/common/math/ApacheBenchmark.java249
-rw-r--r--guava-tests/benchmark/com/google/common/math/BigIntegerMathBenchmark.java119
-rw-r--r--guava-tests/benchmark/com/google/common/math/BigIntegerMathRoundingBenchmark.java93
-rw-r--r--guava-tests/benchmark/com/google/common/math/DoubleMathBenchmark.java90
-rw-r--r--guava-tests/benchmark/com/google/common/math/DoubleMathRoundingBenchmark.java92
-rw-r--r--guava-tests/benchmark/com/google/common/math/IntMathBenchmark.java103
-rw-r--r--guava-tests/benchmark/com/google/common/math/IntMathRoundingBenchmark.java93
-rw-r--r--guava-tests/benchmark/com/google/common/math/LongMathBenchmark.java106
-rw-r--r--guava-tests/benchmark/com/google/common/math/LongMathRoundingBenchmark.java93
9 files changed, 0 insertions, 1038 deletions
diff --git a/guava-tests/benchmark/com/google/common/math/ApacheBenchmark.java b/guava-tests/benchmark/com/google/common/math/ApacheBenchmark.java
deleted file mode 100644
index 7580058..0000000
--- a/guava-tests/benchmark/com/google/common/math/ApacheBenchmark.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * 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 com.google.common.math;
-
-import static com.google.common.math.MathBenchmarking.ARRAY_MASK;
-import static com.google.common.math.MathBenchmarking.ARRAY_SIZE;
-import static com.google.common.math.MathBenchmarking.RANDOM_SOURCE;
-import static com.google.common.math.MathBenchmarking.randomBigInteger;
-import static com.google.common.math.MathBenchmarking.randomNonNegativeBigInteger;
-
-import com.google.caliper.Param;
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-import com.google.common.math.DoubleMath;
-import com.google.common.math.IntMath;
-import com.google.common.math.LongMath;
-
-/**
- * Benchmarks against the Apache Commons Math utilities.
- *
- * <p>Note: the Apache benchmarks are not open sourced to avoid the extra dependency.
- *
- * @author Louis Wasserman
- */
-public class ApacheBenchmark extends SimpleBenchmark {
- private enum Impl {
- GUAVA {
- @Override
- public double factorialDouble(int n) {
- return DoubleMath.factorial(n);
- }
-
- @Override
- public int gcdInt(int a, int b) {
- return IntMath.gcd(a, b);
- }
-
- @Override
- public long gcdLong(long a, long b) {
- return LongMath.gcd(a, b);
- }
-
- @Override
- public long binomialCoefficient(int n, int k) {
- return LongMath.binomial(n, k);
- }
-
- @Override
- public boolean noAddOverflow(int a, int b) {
- try {
- IntMath.checkedAdd(a, b);
- return true;
- } catch (ArithmeticException e) {
- return false;
- }
- }
-
- @Override
- public boolean noAddOverflow(long a, long b) {
- try {
- LongMath.checkedAdd(a, b);
- return true;
- } catch (ArithmeticException e) {
- return false;
- }
- }
-
- @Override
- public boolean noMulOverflow(int a, int b) {
- try {
- IntMath.checkedMultiply(a, b);
- return true;
- } catch (ArithmeticException e) {
- return false;
- }
- }
-
- @Override
- public boolean noMulOverflow(long a, long b) {
- try {
- LongMath.checkedMultiply(a, b);
- return true;
- } catch (ArithmeticException e) {
- return false;
- }
- }
- };
-
- public abstract double factorialDouble(int n);
-
- public abstract long binomialCoefficient(int n, int k);
-
- public abstract int gcdInt(int a, int b);
-
- public abstract long gcdLong(long a, long b);
-
- public abstract boolean noAddOverflow(int a, int b);
-
- public abstract boolean noAddOverflow(long a, long b);
-
- public abstract boolean noMulOverflow(int a, int b);
-
- public abstract boolean noMulOverflow(long a, long b);
- }
-
- private final int[] factorials = new int[ARRAY_SIZE];
- private final int[][] binomials = new int[ARRAY_SIZE][2];
- private final int[][] nonnegInt = new int[ARRAY_SIZE][2];
- private final long[][] nonnegLong = new long[ARRAY_SIZE][2];
- private final int[][] intsToAdd = new int[ARRAY_SIZE][2];
- private final int[][] intsToMul = new int[ARRAY_SIZE][2];
- private final long[][] longsToAdd = new long[ARRAY_SIZE][2];
- private final long[][] longsToMul = new long[ARRAY_SIZE][2];
-
- @Param({"APACHE", "GUAVA"})
- Impl impl;
-
- @Override
- protected void setUp() {
- for (int i = 0; i < ARRAY_SIZE; i++) {
- factorials[i] = RANDOM_SOURCE.nextInt(200);
- for (int j = 0; j < 2; j++) {
- nonnegInt[i][j] = randomNonNegativeBigInteger(Integer.SIZE - 2).intValue();
- nonnegLong[i][j] = randomNonNegativeBigInteger(Long.SIZE - 2).longValue();
- }
- do {
- for (int j = 0; j < 2; j++) {
- intsToAdd[i][j] = randomBigInteger(Integer.SIZE - 2).intValue();
- }
- } while (!Impl.GUAVA.noAddOverflow(intsToAdd[i][0], intsToAdd[i][1]));
- do {
- for (int j = 0; j < 2; j++) {
- longsToAdd[i][j] = randomBigInteger(Long.SIZE - 2).longValue();
- }
- } while (!Impl.GUAVA.noAddOverflow(longsToAdd[i][0], longsToAdd[i][1]));
- do {
- for (int j = 0; j < 2; j++) {
- intsToMul[i][j] = randomBigInteger(Integer.SIZE - 2).intValue();
- }
- } while (!Impl.GUAVA.noMulOverflow(intsToMul[i][0], intsToMul[i][1]));
- do {
- for (int j = 0; j < 2; j++) {
- longsToMul[i][j] = randomBigInteger(Long.SIZE - 2).longValue();
- }
- } while (!Impl.GUAVA.noMulOverflow(longsToMul[i][0], longsToMul[i][1]));
-
- int k = binomials[i][1] = RANDOM_SOURCE.nextInt(MathBenchmarking.biggestBinomials.length);
- binomials[i][0] = RANDOM_SOURCE.nextInt(MathBenchmarking.biggestBinomials[k] - k) + k;
- }
- }
-
- public long timeFactorialDouble(int reps) {
- long tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += Double.doubleToRawLongBits(impl.factorialDouble(factorials[j]));
- }
- return tmp;
- }
-
- public int timeIntGCD(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += impl.gcdInt(nonnegInt[j][0], nonnegInt[j][1]);
- }
- return tmp;
- }
-
- public long timeLongGCD(int reps) {
- long tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += impl.gcdLong(nonnegLong[j][0], nonnegLong[j][1]);
- }
- return tmp;
- }
-
- public long timeBinomialCoefficient(int reps) {
- long tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += impl.binomialCoefficient(binomials[j][0], binomials[j][1]);
- }
- return tmp;
- }
-
- public int timeIntAddOverflow(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- if (impl.noAddOverflow(intsToAdd[j][0], intsToAdd[j][1])) {
- tmp++;
- }
- }
- return tmp;
- }
-
- public int timeLongAddOverflow(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- if (impl.noAddOverflow(longsToAdd[j][0], longsToAdd[j][1])) {
- tmp++;
- }
- }
- return tmp;
- }
-
- public int timeIntMulOverflow(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- if (impl.noMulOverflow(intsToMul[j][0], intsToMul[j][1])) {
- tmp++;
- }
- }
- return tmp;
- }
-
- public int timeLongMulOverflow(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- if (impl.noMulOverflow(longsToMul[j][0], longsToMul[j][1])) {
- tmp++;
- }
- }
- return tmp;
- }
-
- public static void main(String[] args) {
- Runner.main(ApacheBenchmark.class, args);
- }
-}
diff --git a/guava-tests/benchmark/com/google/common/math/BigIntegerMathBenchmark.java b/guava-tests/benchmark/com/google/common/math/BigIntegerMathBenchmark.java
deleted file mode 100644
index 71095e5..0000000
--- a/guava-tests/benchmark/com/google/common/math/BigIntegerMathBenchmark.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * 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 com.google.common.math;
-
-import static com.google.common.math.MathBenchmarking.ARRAY_MASK;
-import static com.google.common.math.MathBenchmarking.ARRAY_SIZE;
-import static com.google.common.math.MathBenchmarking.RANDOM_SOURCE;
-import static java.math.RoundingMode.CEILING;
-
-import com.google.caliper.Param;
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-import com.google.common.math.BigIntegerMath;
-import com.google.common.math.IntMath;
-import com.google.common.math.LongMath;
-
-import java.math.BigInteger;
-
-/**
- * Benchmarks for the non-rounding methods of {@code BigIntegerMath}.
- *
- * @author Louis Wasserman
- */
-public class BigIntegerMathBenchmark extends SimpleBenchmark {
- private static final int[] factorials = new int[ARRAY_SIZE];
- private static final int[] slowFactorials = new int[ARRAY_SIZE];
- private static final int[] binomials = new int[ARRAY_SIZE];
-
- @Param({"50", "1000", "10000"})
- int factorialBound;
-
- @Override
- protected void setUp() {
- for (int i = 0; i < ARRAY_SIZE; i++) {
- factorials[i] = RANDOM_SOURCE.nextInt(factorialBound);
- slowFactorials[i] = RANDOM_SOURCE.nextInt(factorialBound);
- binomials[i] = RANDOM_SOURCE.nextInt(factorials[i] + 1);
- }
- }
-
- /**
- * Previous version of BigIntegerMath.factorial, kept for timing purposes.
- */
- private static BigInteger slowFactorial(int n) {
- if (n <= 20) {
- return BigInteger.valueOf(LongMath.factorial(n));
- } else {
- int k = 20;
- return BigInteger.valueOf(LongMath.factorial(k)).multiply(slowFactorial(k, n));
- }
- }
-
- /**
- * Returns the product of {@code n1} exclusive through {@code n2} inclusive.
- */
- private static BigInteger slowFactorial(int n1, int n2) {
- assert n1 <= n2;
- if (IntMath.log2(n2, CEILING) * (n2 - n1) < Long.SIZE - 1) {
- // the result will definitely fit into a long
- long result = 1;
- for (int i = n1 + 1; i <= n2; i++) {
- result *= i;
- }
- return BigInteger.valueOf(result);
- }
-
- /*
- * We want each multiplication to have both sides with approximately the same number of digits.
- * Currently, we just divide the range in half.
- */
- int mid = (n1 + n2) >>> 1;
- return slowFactorial(n1, mid).multiply(slowFactorial(mid, n2));
- }
-
- public int timeSlowFactorial(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += slowFactorial(slowFactorials[j]).intValue();
- }
- return tmp;
- }
-
- public int timeFactorial(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += BigIntegerMath.factorial(factorials[j]).intValue();
- }
- return tmp;
- }
-
- public int timeBinomial(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & 0xffff;
- tmp += BigIntegerMath.binomial(factorials[j], binomials[j]).intValue();
- }
- return tmp;
- }
-
- public static void main(String[] args) {
- Runner.main(BigIntegerMathBenchmark.class, args);
- }
-}
diff --git a/guava-tests/benchmark/com/google/common/math/BigIntegerMathRoundingBenchmark.java b/guava-tests/benchmark/com/google/common/math/BigIntegerMathRoundingBenchmark.java
deleted file mode 100644
index c7b7df5..0000000
--- a/guava-tests/benchmark/com/google/common/math/BigIntegerMathRoundingBenchmark.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * 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 com.google.common.math;
-
-import static com.google.common.math.MathBenchmarking.ARRAY_MASK;
-import static com.google.common.math.MathBenchmarking.ARRAY_SIZE;
-import static com.google.common.math.MathBenchmarking.randomNonZeroBigInteger;
-import static com.google.common.math.MathBenchmarking.randomPositiveBigInteger;
-
-import com.google.caliper.Param;
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-import com.google.common.math.BigIntegerMath;
-
-import java.math.BigInteger;
-import java.math.RoundingMode;
-
-/**
- * Benchmarks for the rounding methods of {@code BigIntegerMath}.
- *
- * @author Louis Wasserman
- */
-public class BigIntegerMathRoundingBenchmark extends SimpleBenchmark {
- private static final BigInteger[] nonzero1 = new BigInteger[ARRAY_SIZE];
- private static final BigInteger[] nonzero2 = new BigInteger[ARRAY_SIZE];
- private static final BigInteger[] positive = new BigInteger[ARRAY_SIZE];
-
- @Param({"DOWN", "UP", "FLOOR", "CEILING", "HALF_EVEN", "HALF_UP", "HALF_DOWN"})
- RoundingMode mode;
-
- @Override
- protected void setUp() {
- for (int i = 0; i < ARRAY_SIZE; i++) {
- positive[i] = randomPositiveBigInteger(1024);
- nonzero1[i] = randomNonZeroBigInteger(1024);
- nonzero2[i] = randomNonZeroBigInteger(1024);
- }
- }
-
- public int timeLog2(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += BigIntegerMath.log2(positive[j], mode);
- }
- return tmp;
- }
-
- public int timeLog10(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += BigIntegerMath.log10(positive[j], mode);
- }
- return tmp;
- }
-
- public int timeSqrt(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += BigIntegerMath.sqrt(positive[j], mode).intValue();
- }
- return tmp;
- }
-
- public int timeDivide(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += BigIntegerMath.divide(nonzero1[j], nonzero2[j], mode).intValue();
- }
- return tmp;
- }
-
- public static void main(String[] args) {
- Runner.main(BigIntegerMathRoundingBenchmark.class, args);
- }
-}
diff --git a/guava-tests/benchmark/com/google/common/math/DoubleMathBenchmark.java b/guava-tests/benchmark/com/google/common/math/DoubleMathBenchmark.java
deleted file mode 100644
index 12e24a3..0000000
--- a/guava-tests/benchmark/com/google/common/math/DoubleMathBenchmark.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * 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 com.google.common.math;
-
-import static com.google.common.math.MathBenchmarking.ARRAY_MASK;
-import static com.google.common.math.MathBenchmarking.ARRAY_SIZE;
-import static com.google.common.math.MathBenchmarking.RANDOM_SOURCE;
-import static com.google.common.math.MathBenchmarking.randomDouble;
-import static com.google.common.math.MathBenchmarking.randomPositiveDouble;
-
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-
-/**
- * Tests for the non-rounding methods of {@code DoubleMath}.
- *
- * @author Louis Wasserman
- */
-public class DoubleMathBenchmark extends SimpleBenchmark {
- private static final double[] positiveDoubles = new double[ARRAY_SIZE];
- private static final int[] factorials = new int[ARRAY_SIZE];
- private static final double [] doubles = new double[ARRAY_SIZE];
-
- @Override
- protected void setUp() {
- for (int i = 0; i < ARRAY_SIZE; i++) {
- positiveDoubles[i] = randomPositiveDouble();
- doubles[i] = randomDouble(Long.SIZE);
- factorials[i] = RANDOM_SOURCE.nextInt(100);
- }
- }
-
- public long timeLog2(int reps) {
- long tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += Double.doubleToRawLongBits(DoubleMath.log2(positiveDoubles[j]));
- }
- return tmp;
- }
-
- public long timeFactorial(int reps) {
- long tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += Double.doubleToRawLongBits(DoubleMath.factorial(factorials[j]));
- }
- return tmp;
- }
-
- public int timeIsMathematicalInteger(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- if (DoubleMath.isMathematicalInteger(doubles[j])) {
- tmp++;
- }
- }
- return tmp;
- }
-
- public int timeIsPowerOfTwo(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- if (DoubleMath.isPowerOfTwo(doubles[j])) {
- tmp++;
- }
- }
- return tmp;
- }
-
- public static void main(String[] args) {
- Runner.main(DoubleMathBenchmark.class, args);
- }
-}
diff --git a/guava-tests/benchmark/com/google/common/math/DoubleMathRoundingBenchmark.java b/guava-tests/benchmark/com/google/common/math/DoubleMathRoundingBenchmark.java
deleted file mode 100644
index daafb94..0000000
--- a/guava-tests/benchmark/com/google/common/math/DoubleMathRoundingBenchmark.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * 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 com.google.common.math;
-
-import static com.google.common.math.MathBenchmarking.ARRAY_MASK;
-import static com.google.common.math.MathBenchmarking.ARRAY_SIZE;
-import static com.google.common.math.MathBenchmarking.randomDouble;
-import static com.google.common.math.MathBenchmarking.randomPositiveDouble;
-
-import com.google.caliper.Param;
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-import com.google.common.math.DoubleMath;
-
-import java.math.RoundingMode;
-
-/**
- * Benchmarks for the rounding methods of {@code DoubleMath}.
- *
- * @author Louis Wasserman
- */
-public class DoubleMathRoundingBenchmark extends SimpleBenchmark {
- private static final double[] doubleInIntRange = new double[ARRAY_SIZE];
- private static final double[] doubleInLongRange = new double[ARRAY_SIZE];
- private static final double[] positiveDoubles = new double[ARRAY_SIZE];
-
- @Param({"DOWN", "UP", "FLOOR", "CEILING", "HALF_EVEN", "HALF_UP", "HALF_DOWN"})
- RoundingMode mode;
-
- @Override
- protected void setUp() {
- for (int i = 0; i < ARRAY_SIZE; i++) {
- doubleInIntRange[i] = randomDouble(Integer.SIZE - 2);
- doubleInLongRange[i] = randomDouble(Long.SIZE - 2);
- positiveDoubles[i] = randomPositiveDouble();
- }
- }
-
- public int timeRoundToInt(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += DoubleMath.roundToInt(doubleInIntRange[j], mode);
- }
- return tmp;
- }
-
- public long timeRoundToLong(int reps) {
- long tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += DoubleMath.roundToLong(doubleInLongRange[j], mode);
- }
- return tmp;
- }
-
- public int timeRoundToBigInteger(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += DoubleMath.roundToBigInteger(positiveDoubles[j], mode).intValue();
- }
- return tmp;
- }
-
- public int timeLog2Round(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += DoubleMath.log2(positiveDoubles[j], mode);
- }
- return tmp;
- }
-
- public static void main(String[] args) {
- Runner.main(DoubleMathRoundingBenchmark.class, args);
- }
-}
diff --git a/guava-tests/benchmark/com/google/common/math/IntMathBenchmark.java b/guava-tests/benchmark/com/google/common/math/IntMathBenchmark.java
deleted file mode 100644
index 9f439b4..0000000
--- a/guava-tests/benchmark/com/google/common/math/IntMathBenchmark.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * 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 com.google.common.math;
-
-import static com.google.common.math.MathBenchmarking.ARRAY_MASK;
-import static com.google.common.math.MathBenchmarking.ARRAY_SIZE;
-import static com.google.common.math.MathBenchmarking.RANDOM_SOURCE;
-import static com.google.common.math.MathBenchmarking.randomExponent;
-import static com.google.common.math.MathBenchmarking.randomNonNegativeBigInteger;
-import static com.google.common.math.MathBenchmarking.randomPositiveBigInteger;
-
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-import com.google.common.math.IntMath;
-
-/**
- * Benchmarks for the non-rounding methods of {@code IntMath}.
- *
- * @author Louis Wasserman
- */
-public class IntMathBenchmark extends SimpleBenchmark {
- private static int[] exponent = new int[ARRAY_SIZE];
- private static int[] factorial = new int[ARRAY_SIZE];
- private static int[] binomial = new int[ARRAY_SIZE];
- private static final int[] positive = new int[ARRAY_SIZE];
- private static final int[] nonnegative = new int[ARRAY_SIZE];
- private static final int[] ints = new int[ARRAY_SIZE];
-
- @Override
- protected void setUp() {
- for (int i = 0; i < ARRAY_SIZE; i++) {
- exponent[i] = randomExponent();
- factorial[i] = RANDOM_SOURCE.nextInt(50);
- binomial[i] = RANDOM_SOURCE.nextInt(factorial[i] + 1);
- positive[i] = randomPositiveBigInteger(Integer.SIZE - 2).intValue();
- nonnegative[i] = randomNonNegativeBigInteger(Integer.SIZE - 2).intValue();
- ints[i] = RANDOM_SOURCE.nextInt();
- }
- }
-
- public int timePow(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += IntMath.pow(positive[j], exponent[j]);
- }
- return tmp;
- }
-
- public int timeMod(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += IntMath.mod(ints[j], positive[j]);
- }
- return tmp;
- }
-
- public int timeGCD(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += IntMath.gcd(nonnegative[j], positive[j]);
- }
- return tmp;
- }
-
- public int timeFactorial(int reps){
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += IntMath.factorial(factorial[j]);
- }
- return tmp;
- }
-
- public int timeBinomial(int reps){
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += IntMath.binomial(factorial[j], binomial[j]);
- }
- return tmp;
- }
-
- public static void main(String[] args) {
- Runner.main(IntMathBenchmark.class, args);
- }
-}
diff --git a/guava-tests/benchmark/com/google/common/math/IntMathRoundingBenchmark.java b/guava-tests/benchmark/com/google/common/math/IntMathRoundingBenchmark.java
deleted file mode 100644
index 1bbefbe..0000000
--- a/guava-tests/benchmark/com/google/common/math/IntMathRoundingBenchmark.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * 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 com.google.common.math;
-
-import static com.google.common.math.MathBenchmarking.ARRAY_MASK;
-import static com.google.common.math.MathBenchmarking.ARRAY_SIZE;
-import static com.google.common.math.MathBenchmarking.RANDOM_SOURCE;
-import static com.google.common.math.MathBenchmarking.randomNonZeroBigInteger;
-import static com.google.common.math.MathBenchmarking.randomPositiveBigInteger;
-
-import com.google.caliper.Param;
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-import com.google.common.math.IntMath;
-
-import java.math.RoundingMode;
-
-/**
- * Benchmarks for the rounding methods of {@code IntMath}.
- *
- * @author Louis Wasserman
- */
-public class IntMathRoundingBenchmark extends SimpleBenchmark {
- private static final int[] positive = new int[ARRAY_SIZE];
- private static final int[] nonzero = new int[ARRAY_SIZE];
- private static final int[] ints = new int[ARRAY_SIZE];
-
- @Override
- protected void setUp() {
- for (int i = 0; i < ARRAY_SIZE; i++) {
- positive[i] = randomPositiveBigInteger(Integer.SIZE - 2).intValue();
- nonzero[i] = randomNonZeroBigInteger(Integer.SIZE - 2).intValue();
- ints[i] = RANDOM_SOURCE.nextInt();
- }
- }
-
- @Param({"DOWN", "UP", "FLOOR", "CEILING", "HALF_EVEN", "HALF_UP", "HALF_DOWN"})
- RoundingMode mode;
-
- public int timeLog2(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += IntMath.log2(positive[j], mode);
- }
- return tmp;
- }
-
- public int timeLog10(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += IntMath.log10(positive[j], mode);
- }
- return tmp;
- }
-
- public int timeSqrt(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += IntMath.sqrt(positive[j], mode);
- }
- return tmp;
- }
-
- public int timeDivide(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += IntMath.divide(ints[j], nonzero[j], mode);
- }
- return tmp;
- }
-
- public static void main(String[] args) {
- Runner.main(IntMathRoundingBenchmark.class, args);
- }
-}
diff --git a/guava-tests/benchmark/com/google/common/math/LongMathBenchmark.java b/guava-tests/benchmark/com/google/common/math/LongMathBenchmark.java
deleted file mode 100644
index 3a25a47..0000000
--- a/guava-tests/benchmark/com/google/common/math/LongMathBenchmark.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * 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 com.google.common.math;
-
-import static com.google.common.math.MathBenchmarking.ARRAY_MASK;
-import static com.google.common.math.MathBenchmarking.ARRAY_SIZE;
-import static com.google.common.math.MathBenchmarking.RANDOM_SOURCE;
-import static com.google.common.math.MathBenchmarking.randomExponent;
-import static com.google.common.math.MathBenchmarking.randomNonNegativeBigInteger;
-import static com.google.common.math.MathBenchmarking.randomPositiveBigInteger;
-
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-import com.google.common.math.LongMath;
-
-/**
- * Benchmarks for the non-rounding methods of {@code LongMath}.
- *
- * @author Louis Wasserman
- */
-public class LongMathBenchmark extends SimpleBenchmark {
- private static final int[] exponents = new int[ARRAY_SIZE];
- private static final int[] factorialArguments = new int[ARRAY_SIZE];
- private static final int[][] binomialArguments = new int[ARRAY_SIZE][2];
- private static final long[] positive = new long[ARRAY_SIZE];
- private static final long[] nonnegative = new long[ARRAY_SIZE];
- private static final long[] longs = new long[ARRAY_SIZE];
-
- @Override
- protected void setUp() {
- for (int i = 0; i < ARRAY_SIZE; i++) {
- exponents[i] = randomExponent();
- positive[i] = randomPositiveBigInteger(Long.SIZE - 2).longValue();
- nonnegative[i] = randomNonNegativeBigInteger(Long.SIZE - 2).longValue();
- longs[i] = RANDOM_SOURCE.nextLong();
- factorialArguments[i] = RANDOM_SOURCE.nextInt(30);
- binomialArguments[i][1] = RANDOM_SOURCE.nextInt(MathBenchmarking.biggestBinomials.length);
- int k = binomialArguments[i][1];
- binomialArguments[i][0] =
- RANDOM_SOURCE.nextInt(MathBenchmarking.biggestBinomials[k] - k) + k;
- }
- }
-
- public int timePow(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += LongMath.pow(positive[j], exponents[j]);
- }
- return tmp;
- }
-
- public int timeMod(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += LongMath.mod(longs[j], positive[j]);
- }
- return tmp;
- }
-
- public int timeGCD(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += LongMath.mod(nonnegative[j], positive[j]);
- }
- return tmp;
- }
-
- public int timeFactorial(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += LongMath.factorial(factorialArguments[j]);
- }
- return tmp;
- }
-
- public int timeBinomial(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += LongMath.binomial(binomialArguments[j][0], binomialArguments[j][1]);
- }
- return tmp;
- }
-
- public static void main(String[] args) {
- Runner.main(LongMathBenchmark.class, args);
- }
-}
diff --git a/guava-tests/benchmark/com/google/common/math/LongMathRoundingBenchmark.java b/guava-tests/benchmark/com/google/common/math/LongMathRoundingBenchmark.java
deleted file mode 100644
index d859d35..0000000
--- a/guava-tests/benchmark/com/google/common/math/LongMathRoundingBenchmark.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * 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 com.google.common.math;
-
-import static com.google.common.math.MathBenchmarking.ARRAY_MASK;
-import static com.google.common.math.MathBenchmarking.ARRAY_SIZE;
-import static com.google.common.math.MathBenchmarking.RANDOM_SOURCE;
-import static com.google.common.math.MathBenchmarking.randomNonZeroBigInteger;
-import static com.google.common.math.MathBenchmarking.randomPositiveBigInteger;
-
-import com.google.caliper.Param;
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-import com.google.common.math.LongMath;
-
-import java.math.RoundingMode;
-
-/**
- * Benchmarks for the rounding methods of {@code LongMath}.
- *
- * @author Louis Wasserman
- */
-public class LongMathRoundingBenchmark extends SimpleBenchmark {
- @Param({"DOWN", "UP", "FLOOR", "CEILING", "HALF_EVEN", "HALF_UP", "HALF_DOWN"})
- RoundingMode mode;
-
- private static final long[] positive = new long[ARRAY_SIZE];
- private static final long[] nonzero = new long[ARRAY_SIZE];
- private static final long[] longs = new long[ARRAY_SIZE];
-
- @Override
- protected void setUp() {
- for (int i = 0; i < ARRAY_SIZE; i++) {
- positive[i] = randomPositiveBigInteger(Long.SIZE - 2).longValue();
- nonzero[i] = randomNonZeroBigInteger(Long.SIZE - 2).longValue();
- longs[i] = RANDOM_SOURCE.nextLong();
- }
- }
-
- public int timeLog2(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += LongMath.log2(positive[j], mode);
- }
- return tmp;
- }
-
- public int timeLog10(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += LongMath.log10(positive[j], mode);
- }
- return tmp;
- }
-
- public int timeSqrt(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += LongMath.sqrt(positive[j], mode);
- }
- return tmp;
- }
-
- public int timeDivide(int reps) {
- int tmp = 0;
- for (int i = 0; i < reps; i++) {
- int j = i & ARRAY_MASK;
- tmp += LongMath.divide(longs[j], nonzero[j], mode);
- }
- return tmp;
- }
-
- public static void main(String[] args) {
- Runner.main(LongMathRoundingBenchmark.class, args);
- }
-}