我在JMH中实施了快速测试
package org.sample;
import org.openjdk.jmh.annotations.Benchmark;
import java.lang.Math;
public class MyBenchmark {
@Benchmark
public void testMethod() {
// This is a demo/sample template for building your JMH benchmarks. Edit as needed.
// Put your benchmark code here.
Math.sin(1);
}
}
对oracle-jvm-7和oracle-jvm-8进行基准测试(Gentoo Linux,Linux capitan 4.5.3-gentoo#2 SMP Wed May 11 09:57:24 EEST 2016 x86_64 Intel(R)Core(TM) i5-4590 CPU @ 3.30GHz GenuineIntel GNU / Linux)
得到了这些结果:
============================================================================================
oracle-jvm-7
Result "testMethod":
35528416.197 ±(99.9%) 645918.757 ops/s [Average]
(min, avg, max) = (14648664.448, 35528416.197, 37358723.432), stdev = 2734860.462
CI (99.9%): [34882497.440, 36174334.954] (assumes normal distribution)
# Run complete. Total time: 00:06:41
Benchmark Mode Cnt Score Error Units
MyBenchmark.testMethod thrpt 200 35528416.197 ± 645918.757 ops/s
============================================================================================
oracle-jvm-8
Result "testMethod":
25471034.505 ±(99.9%) 883625.172 ops/s [Average]
(min, avg, max) = (10388072.812, 25471034.505, 27847466.635), stdev = 3741324.307
CI (99.9%): [24587409.334, 26354659.677] (assumes normal distribution)
# Run complete. Total time: 00:06:42
Benchmark Mode Cnt Score Error Units
MyBenchmark.testMethod thrpt 200 25471034.505 ± 883625.172 ops/s
JVM7上有Math.sin
给出35528416.197 ops / s,而JVM8上只有25471034.505 ops / s,是否有任何具体原因?