Java 在使用JMH状态时,如何观察共享和非共享情况下的“显著差异”?

Java 在使用JMH状态时,如何观察共享和非共享情况下的“显著差异”?,java,benchmarking,jmh,Java,Benchmarking,Jmh,我看一下工具 在样本文件中,他们说: ============================== HOW TO RUN THIS TEST: ==================================== You are expected to see the drastic difference in shared and unshared cases, because you either contend for single memory location, or

我看一下工具

在样本文件中,他们说:

  ============================== HOW TO RUN THIS TEST: ====================================

  You are expected to see the drastic difference in shared and unshared cases,
  because you either contend for single memory location, or not. This effect
  is more articulated on large machines.

  You can run this test:

  a) Via the command line:
     $ mvn clean install
     $ java -jar target/benchmarks.jar JMHSample_03 -wi 5 -i 5 -t 4 -f 1
     (we requested 5 measurement/warmup iterations, with 4 threads, single fork)
我对java 1.8.20.0和Intel i5-4670K CPU@3.40GHz的测试结果

# Run complete. Total time: 00:00:24

Benchmark                                   Mode  Samples           Score  Score error  Units
o.s.JMHSample_03_States.measureShared      thrpt        5  1547894580.996  3632128.044  ops/s
o.s.JMHSample_03_States.measureUnshared    thrpt        5  1571371998.011  6150584.658  ops/s

最大的区别是什么?measureShared 1547894580和measureUnshared 15713998之间的差异小于2%

好吧,您确定您请求了4个线程,如示例所示吗?@Aleksey Shipilev是的,当然。看看这里,我也注意到,比别人有不同的结果可能是我需要注册的缺陷跟踪?这听起来像一个环境问题,看起来还不像一个缺陷。您的系统有多少个CPU?请提供您的/proc/cpuinfo?4芯。