Output timing info as a ratio with respect to StrictMath benchmark result.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1063019 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2011-01-24 22:15:44 +00:00
parent a3f6c210e3
commit 7b09face70
1 changed files with 80 additions and 265 deletions

View File

@ -27,565 +27,380 @@ import org.junit.Ignore;
*/ */
public class FastMathTestPerformance { public class FastMathTestPerformance {
private static final int RUNS = 10000000; private static final int RUNS = 10000000;
private static final double SCALE = 1000d / RUNS;
@Ignore private void print(String funcName) {
public void testPerformance() { System.out.print(funcName + " ");
final int numberOfRuns = 10000000; }
for (int j = 0; j < 10; j++) { private void print(long time, long unitTime) {
double x = 0; final double ratio = time / (double) unitTime;
long time = System.currentTimeMillis(); System.out.print(time + " " + ratio + " ");
for (int i = 0; i < numberOfRuns; i++) }
x += StrictMath.log(Math.PI + i/* 1.0 + i/1e9 */); private void println(long time, long unitTime) {
time = System.currentTimeMillis() - time; print(time, unitTime);
System.out.print("StrictMath.log " + time + "\t" + x + "\t"); System.out.println();
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.log(Math.PI + i/* 1.0 + i/1e9 */);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.log " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += StrictMath.pow(Math.PI + i / 1e6, i / 1e6);
time = System.currentTimeMillis() - time;
System.out.print("StrictMath.pow " + time + "\t" + x + "\t");
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.pow(Math.PI + i / 1e6, i / 1e6);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.pow " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += StrictMath.exp(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.print("StrictMath.exp " + time + "\t" + x + "\t");
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.exp(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.exp " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += StrictMath.sin(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.print("StrictMath.sin " + time + "\t" + x + "\t");
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.sin(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.sin " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += StrictMath.asin(i / 10000000.0);
time = System.currentTimeMillis() - time;
System.out.print("StrictMath.asin " + time + "\t" + x + "\t");
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.asin(i / 10000000.0);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.asin " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += StrictMath.cos(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.print("StrictMath.cos " + time + "\t" + x + "\t");
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.cos(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.cos " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += StrictMath.acos(i / 10000000.0);
time = System.currentTimeMillis() - time;
System.out.print("StrictMath.acos " + time + "\t" + x + "\t");
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.acos(i / 10000000.0);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.acos " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += StrictMath.tan(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.print("StrictMath.tan " + time + "\t" + x + "\t");
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.tan(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.tan " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += StrictMath.atan(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.print("StrictMath.atan " + time + "\t" + x + "\t");
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.atan(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.atan " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += StrictMath.cbrt(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.print("StrictMath.cbrt " + time + "\t" + x + "\t");
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.cbrt(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.cbrt " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += StrictMath.cosh(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.print("StrictMath.cosh " + time + "\t" + x + "\t");
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.cosh(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.cosh " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += StrictMath.sinh(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.print("StrictMath.sinh " + time + "\t" + x + "\t");
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.sinh(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.sinh " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += StrictMath.tanh(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.print("StrictMath.tanh " + time + "\t" + x + "\t");
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.tanh(i / 1000000.0);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.tanh " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += StrictMath.expm1(-i / 100000.0);
time = System.currentTimeMillis() - time;
System.out.print("StrictMath.expm1 " + time + "\t" + x + "\t");
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.expm1(-i / 100000.0);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.expm1 " + time + "\t" + x);
x = 0;
time = System.currentTimeMillis();
for (int i = 0; i < numberOfRuns; i++)
x += FastMath.expm1(-i / 100000.0);
time = System.currentTimeMillis() - time;
System.out.println("FastMath.expm1 " + time + "\t" + x);
}
} }
@Test @Test
public void testLog() { public void testLog() {
System.out.print("log "); print("log");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.log(Math.PI + i/* 1.0 + i/1e9 */); x += StrictMath.log(Math.PI + i/* 1.0 + i/1e9 */);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.log(Math.PI + i/* 1.0 + i/1e9 */); x += FastMath.log(Math.PI + i/* 1.0 + i/1e9 */);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.log(Math.PI + i/* 1.0 + i/1e9 */); x += Math.log(Math.PI + i/* 1.0 + i/1e9 */);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
@Test @Test
public void testPow() { public void testPow() {
System.out.print("pow "); print("pow");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.pow(Math.PI + i / 1e6, i / 1e6); x += StrictMath.pow(Math.PI + i / 1e6, i / 1e6);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.pow(Math.PI + i / 1e6, i / 1e6); x += FastMath.pow(Math.PI + i / 1e6, i / 1e6);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.pow(Math.PI + i / 1e6, i / 1e6); x += Math.pow(Math.PI + i / 1e6, i / 1e6);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
@Test @Test
public void testExp() { public void testExp() {
System.out.print("exp "); print("exp");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.exp(i / 1000000.0); x += StrictMath.exp(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.exp(i / 1000000.0); x += FastMath.exp(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.exp(i / 1000000.0); x += Math.exp(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
@Test @Test
public void testSin() { public void testSin() {
System.out.print("sin "); print("sin");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.sin(i / 1000000.0); x += StrictMath.sin(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.sin(i / 1000000.0); x += FastMath.sin(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.sin(i / 1000000.0); x += Math.sin(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
@Test @Test
public void testAsin() { public void testAsin() {
System.out.print("asin "); print("asin");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.asin(i / 10000000.0); x += StrictMath.asin(i / 10000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.asin(i / 10000000.0); x += FastMath.asin(i / 10000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.asin(i / 10000000.0); x += Math.asin(i / 10000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
@Test @Test
public void testCos() { public void testCos() {
System.out.print("cos "); print("cos");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.cos(i / 1000000.0); x += StrictMath.cos(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.cos(i / 1000000.0); x += FastMath.cos(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.cos(i / 1000000.0); x += Math.cos(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
@Test @Test
public void testAcos() { public void testAcos() {
System.out.print("acos "); print("acos");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.acos(i / 10000000.0); x += StrictMath.acos(i / 10000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.acos(i / 10000000.0); x += FastMath.acos(i / 10000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.acos(i / 10000000.0); x += Math.acos(i / 10000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
@Test @Test
public void testTan() { public void testTan() {
System.out.print("tan "); print("tan");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.tan(i / 1000000.0); x += StrictMath.tan(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.tan(i / 1000000.0); x += FastMath.tan(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.tan(i / 1000000.0); x += Math.tan(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
@Test @Test
public void testAtan() { public void testAtan() {
System.out.print("atan "); print("atan");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.atan(i / 1000000.0); x += StrictMath.atan(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.atan(i / 1000000.0); x += FastMath.atan(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.atan(i / 1000000.0); x += Math.atan(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
@Test @Test
public void testCbrt() { public void testCbrt() {
System.out.print("cbrt "); print("cbrt");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.cbrt(i / 1000000.0); x += StrictMath.cbrt(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.cbrt(i / 1000000.0); x += FastMath.cbrt(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.cbrt(i / 1000000.0); x += Math.cbrt(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
@Test @Test
public void testCosh() { public void testCosh() {
System.out.print("cosh "); print("cosh");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.cosh(i / 1000000.0); x += StrictMath.cosh(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.cosh(i / 1000000.0); x += FastMath.cosh(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.cosh(i / 1000000.0); x += Math.cosh(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
@Test @Test
public void testSinh() { public void testSinh() {
System.out.print("sinh "); print("sinh");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.sinh(i / 1000000.0); x += StrictMath.sinh(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.sinh(i / 1000000.0); x += FastMath.sinh(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.sinh(i / 1000000.0); x += Math.sinh(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
@Test @Test
public void testTanh() { public void testTanh() {
System.out.print("tanh "); print("tanh");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.tanh(i / 1000000.0); x += StrictMath.tanh(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.tanh(i / 1000000.0); x += FastMath.tanh(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.tanh(i / 1000000.0); x += Math.tanh(i / 1000000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
@Test @Test
public void testExpm1() { public void testExpm1() {
System.out.print("expm1 "); print("expm1");
double x = 0; double x = 0;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += StrictMath.expm1(-i / 100000.0); x += StrictMath.expm1(-i / 100000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); long unitTime = time;
print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += FastMath.expm1(-i / 100000.0); x += FastMath.expm1(-i / 100000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.print(time * SCALE + " "); print(time, unitTime);
x = 0; x = 0;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
for (int i = 0; i < RUNS; i++) for (int i = 0; i < RUNS; i++)
x += Math.expm1(-i / 100000.0); x += Math.expm1(-i / 100000.0);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println(time * SCALE); println(time, unitTime);
} }
} }