我是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?
答案 0 :(得分:2)
我猜这是一个CLASSPATH混淆。您可能在CLASSPATH上有一个旧的Guava版本,而Caliper需要14.0(其中添加了方法elapsed(TimeUnit)
)。更新,就是这样。
如果您无法更新,请确保Caliper的Guava首先出现......不知道会出现什么问题,但我可能会工作。