in src/userguide/java/org/apache/commons/math4/userguide/JdkMathTestPerformance.java [650:1142]
private static void testSimpleBenchmark() {
final String SM = "StrictMath";
final String M = "Math";
final String FM = "JdkMath";
final int maxWidth = 15;
final int numStat = 100;
final int numCall = RUNS / numStat;
final double x = Math.random();
final double y = Math.random();
PerfTestUtils.timeAndReport("log",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.log(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.log(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.log(x);
}
});
PerfTestUtils.timeAndReport("log10",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.log10(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.log10(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.log10(x);
}
});
PerfTestUtils.timeAndReport("log1p",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.log1p(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.log1p(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.log1p(x);
}
});
PerfTestUtils.timeAndReport("pow",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.pow(x, y);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.pow(x, y);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.pow(x, y);
}
});
PerfTestUtils.timeAndReport("exp",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.exp(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.exp(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.exp(x);
}
});
PerfTestUtils.timeAndReport("sin",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.sin(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.sin(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.sin(x);
}
});
PerfTestUtils.timeAndReport("asin",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.asin(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.asin(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.asin(x);
}
});
PerfTestUtils.timeAndReport("cos",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.cos(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.cos(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.cos(x);
}
});
PerfTestUtils.timeAndReport("acos",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.acos(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.acos(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.acos(x);
}
});
PerfTestUtils.timeAndReport("tan",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.tan(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.tan(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.tan(x);
}
});
PerfTestUtils.timeAndReport("atan",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.atan(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.atan(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.atan(x);
}
});
PerfTestUtils.timeAndReport("atan2",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.atan2(x, y);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.atan2(x, y);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.atan2(x, y);
}
});
PerfTestUtils.timeAndReport("hypot",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.hypot(x, y);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.hypot(x, y);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.hypot(x, y);
}
});
PerfTestUtils.timeAndReport("cbrt",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.cbrt(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.cbrt(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.cbrt(x);
}
});
PerfTestUtils.timeAndReport("sqrt",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.sqrt(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.sqrt(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.sqrt(x);
}
});
PerfTestUtils.timeAndReport("cosh",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.cosh(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.cosh(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.cosh(x);
}
});
PerfTestUtils.timeAndReport("sinh",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.sinh(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.sinh(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.sinh(x);
}
});
PerfTestUtils.timeAndReport("tanh",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.tanh(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.tanh(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.tanh(x);
}
});
PerfTestUtils.timeAndReport("expm1",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.expm1(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.expm1(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.expm1(x);
}
});
PerfTestUtils.timeAndReport("abs",
maxWidth,
numCall,
numStat,
false,
new PerfTestUtils.RunTest(SM) {
@Override
public Double call() throws Exception {
return StrictMath.abs(x);
}
},
new PerfTestUtils.RunTest(M) {
@Override
public Double call() throws Exception {
return Math.abs(x);
}
},
new PerfTestUtils.RunTest(FM) {
@Override
public Double call() throws Exception {
return JdkMath.abs(x);
}
});
}