Java 运行基准测试时发生异常

Java 运行基准测试时发生异常,java,caliper,Java,Caliper,我只是想写一个简单的基准测试- public class IntegerCompareBenchmark extends SimpleBenchmark { private Integer left; private Integer right; @Override protected void setUp() { left = 100; right = 200; }

我只是想写一个简单的基准测试-

public class IntegerCompareBenchmark extends SimpleBenchmark {

        private Integer left;
        private Integer right;

        @Override protected void setUp() {
            left = 100;
            right = 200;
        }

        public int timeIntsCompare(int reps) {
            int val = 0;
            for (int i = 0; i < reps; i++) {
                val += Ints.compare(left, right);
            }
            return val;
        }

        public int timeIntegerCompare(int reps) {
            int val = 0;
            for (int i = 0; i < reps; i++) {
                val += left.compareTo(right);
            }
            return val;
        }


    public static void main(String[] args) throws Exception {
        Runner.main(IntegerCompareBenchmark.class, args);
    }
}
公共类IntegerCompareBenchmark扩展了SimpleBenchmark{
私有整数左;
私有整数权;
@覆盖受保护的无效设置(){
左=100;
右=200;
}
公共int时间INTS比较(int代表){
int-val=0;
对于(int i=0;i
但它失败了,只有一个例外-

Failed to execute java -cp com.google.caliper.InProcessRunner --warmupMillis 3000 --runMillis 1000 --measurementType TIME --marker //ZxJ/ -Dbenchmark=IntsCompare com.poc.IntegerCompareBenchmark
starting Scenario{vm=java, trial=0, benchmark=IntsCompare}
[caliper] [starting warmup]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
[caliper] [starting measured section]
[caliper] [done measured section]
Error: Doing 2x as much work didn't take 2x as much time! Is the JIT optimizing away the body of your benchmark?

Usage: Runner [OPTIONS...] <benchmark>

  <benchmark>: a benchmark class or suite

OPTIONS

  -D<param>=<value>: fix a benchmark parameter to a given value.
        Multiple values can be supplied by separating them with the
        delimiter specified in the --delimiter argument.

        For example: "-Dfoo=bar,baz,bat"

        "benchmark" is a special parameter that can be used to specify
        which benchmark methods to run. For example, if a benchmark has
        the method "timeFoo", it can be run alone by using
        "-Dbenchmark=Foo". "benchmark" also accepts a delimiter
        separated list of methods to run.

  -J<param>=<value>: set a JVM argument to the given value.
        Multiple values can be supplied by separating them with the
        delimiter specified in the --delimiter argument.

        For example: "-JmemoryMax=-Xmx32M,-Xmx512M"

  --delimiter <delimiter>: character or string to use as a delimiter
        for parameter and vm values.
        Default: ","

  --warmupMillis <millis>: duration to warmup each benchmark

  --runMillis <millis>: duration to execute each benchmark

  --captureVmLog: record the VM's just-in-time compiler and GC logs.
        This may slow down or break benchmark display tools.

  --measureMemory: measure the number of allocations done and the amount of
        memory used by invocations of the benchmark.
        Default: off

  --vm <vm>: executable to test benchmark on. Multiple VMs may be passed
        in as a list separated by the delimiter specified in the
        --delimiter argument.

  --timeUnit <unit>: unit of time to use for result. Depends on the units
        defined in the benchmark's getTimeUnitNames() method, if defined.
        Default Options: ns, us, ms, s

  --instanceUnit <unit>: unit to use for allocation instances result.
        Depends on the units defined in the benchmark's
        getInstanceUnitNames() method, if defined.
        Default Options: instances, K instances, M instances, B instances

  --memoryUnit <unit>: unit to use for allocation memory size result.
        Depends on the units defined in the benchmark's
        getMemoryUnitNames() method, if defined.
        Default Options: B, KB, MB, GB

  --saveResults <file/dir>: write results to this file or directory

  --printScore: if present, also display an aggregate score for this run,
        where higher is better. This number has no particular meaning,
        but can be compared to scores from other runs that use the exact
        same arguments.

  --uploadResults <file/dir>: upload this file or directory of files
        to the web app. This argument ends Caliper early and is thus
        incompatible with all other arguments.

  --debug: run without measurement for use with debugger or profiling.

  --debug-reps: fixed number of reps to run with --debug.
        Default: "1000"
[caliper] [scenarios finished]

An exception was thrown from the benchmark code.
com.google.caliper.ConfigurationException: Failed to execute java -cp <class path files> com.google.caliper.InProcessRunner --warmupMillis 3000 --runMillis 1000 --measurementType TIME --marker //ZxJ/ -Dbenchmark=IntsCompare com.poc.IntegerCompareBenchmark
    at com.google.caliper.Runner.measure(Runner.java:309)
    at com.google.caliper.Runner.runScenario(Runner.java:229)
    at com.google.caliper.Runner.runOutOfProcess(Runner.java:378)
    at com.google.caliper.Runner.run(Runner.java:97)
    at com.google.caliper.Runner.main(Runner.java:423)
    at com.google.caliper.Runner.main(Runner.java:440)
    at com.poc.IntegerCompareBenchmark.main(IntegerCompareBenchmark.java:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Process finished with exit code 1
未能执行java-cp com.google.caliper.InProcessRunner--warmupMillis 3000--runMillis 1000--measurementType TIME--marker//ZxJ/-Dbenchmark=IntsCompare com.poc.integercomparebanchmark
开始场景{vm=java,trial=0,benchmark=IntsCompare}
[卡钳][开始预热]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
[卡尺][开始测量部分]
[卡尺][完成测量部分]
错误:做2倍的工作并没有花2倍的时间!JIT优化是否会消除基准的主体?
用法:Runner[选项…]
:基准类或套件
选择权
-D=:将基准参数固定为给定值。
通过使用分隔符分隔多个值,可以提供多个值
在--delimiter参数中指定的分隔符。
例如:“-Dfoo=bar、baz、bat”
“基准”是一个特殊参数,可用于指定
运行哪些基准方法。例如,如果基准测试
方法“timeFoo”,它可以通过使用
“-Dbenchmark=Foo”。“基准”还接受分隔符
要运行的方法的单独列表。
-J=:将JVM参数设置为给定值。
通过使用分隔符分隔多个值,可以提供多个值
在--delimiter参数中指定的分隔符。
例如:“-JmemoryMax=-Xmx32M,-Xmx512M”
--分隔符:用作分隔符的字符或字符串
用于参数和vm值。
默认值:“,”
--预热:每个基准的预热持续时间
--runMillis:执行每个基准的持续时间
--captureVmLog:记录VM的即时编译器和GC日志。
这可能会减慢或破坏基准显示工具。
--度量内存:度量完成的分配数量和分配的数量
基准测试调用使用的内存。
默认值:关闭
--vm:测试基准的可执行文件。可以传递多个VM
在中,作为列表,由中指定的分隔符分隔
--定界符参数。
--timeUnit:用于结果的时间单位。取决于单位
在基准测试的getTimeUnitNames()方法中定义(如果已定义)。
默认选项:ns、us、ms、s
--instanceUnit:用于分配实例结果的单位。
取决于基准中定义的单位
getInstanceUnitNames()方法(如果已定义)。
默认选项:实例、K实例、M实例、B实例
--memoryUnit:用于分配内存大小结果的单位。
取决于基准中定义的单位
getMemoryUnitNames()方法(如果已定义)。
默认选项:B、KB、MB、GB
--saveResults:将结果写入此文件或目录
--printScore:如果存在,还显示此运行的汇总分数,
越高越好。这个