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