我是 caliper 的新手,我想知道我是否可以创建一个主要方法,然后右键单击并选择使用 IntelliJ 的“运行”?
public class Benchmark1 extends Benchmark{
@Param({"10", "100", "1000", "10000"}) private int length;
public void timeNanoTime(int reps) {
for (int i = 0; i < reps; i++) {
System.nanoTime();
}
}
public static void main(String[] args) {
CaliperMain.main(Benchmark1.class, args);
}
}
当我尝试运行上述内容时,出现此错误:
Experiment selection:
Instruments: [allocation, micro]
User parameters: {length=[10, 100, 1000, 10000]}
Virtual machines: [default]
Selection type: Full cartesian product
This selection yields 8 experiments.
Starting experiment 1 of 8: {instrument=allocation, method=NanoTime, vm=default, parameters={length=10}}
java.lang.RuntimeException: java.lang.NoSuchMethodError: com.google.common.base.Stopwatch.elapsed(Ljava/util/concurrent/TimeUnit;)J
at com.google.caliper.runner.ExperimentingCaliperRun.measure(ExperimentingCaliperRun.java:394)
at com.google.caliper.runner.ExperimentingCaliperRun.run(ExperimentingCaliperRun.java:207)
at com.google.caliper.runner.CaliperMain.exitlessMain(CaliperMain.java:131)
at com.google.caliper.runner.CaliperMain.main(CaliperMain.java:78)
at com.google.caliper.runner.CaliperMain.main(CaliperMain.java:66)
at xxxxxxxxxxx(redacted).main(Benchmark1.java:28)
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)
Caused by: java.lang.NoSuchMethodError: com.google.common.base.Stopwatch.elapsed(Ljava/util/concurrent/TimeUnit;)J
at com.google.caliper.runner.ExperimentingCaliperRun.getRemainingTrialNanos(ExperimentingCaliperRun.java:406)
at com.google.caliper.runner.ExperimentingCaliperRun.access$400(ExperimentingCaliperRun.java:95)
at com.google.caliper.runner.ExperimentingCaliperRun$LineConsumer.call(ExperimentingCaliperRun.java:513)
at com.google.caliper.runner.ExperimentingCaliperRun$LineConsumer.call(ExperimentingCaliperRun.java:495)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)
The worker exited without producing data. It has likely crashed. Run with --verbose to see any worker output.
An unexpected exception has been thrown by the caliper runner.
Please see https://sites.google.com/site/caliperusers/issues
Process finished with exit code 1
另外,由于我使用的是 IntelliJ,并且我的卡尺是在 maven 中定义的(即测试范围):
<dependency>
<groupId>com.google.caliper</groupId>
<artifactId>caliper</artifactId>
<version>${caliper-version}</version>
<scope>test</scope>
</dependency>
我将如何从命令行运行 caliper?