8

我试图弄清楚如何使用 Caliper 在 Eclipse 中进行基准测试,但我一无所获。我尝试按照此处找到的 26 分钟教程进行操作:https ://code.google.com/p/caliper/但我很快就迷路了。我已经下载了 Caliper jar 文件,但我不确定它应该在哪个文件夹中。我还下载了 Maven for Eclipse 插件,但我什至不确定这是否有必要。是否可以从 Eclipse 帮助菜单中的“安装新软件..”选项安装 Caliper?我只想能够对我为正在学习的数据结构和算法类创建的一些算法进行非常简单的速度测试。

4

3 回答 3

9

这个答案现在已经过时了。Caliper 在 Windows 中工作了一年多,至少:https ://code.google.com/p/caliper/issues/detail?id=167


卡尺在 Windows 中不起作用。看到这个案例。您需要使用 0.5-rc1 版本,该版本还有其他问题,但仍然很好,并且缺少很多功能,但它确实可以在 Windows 中使用。

完成后,您就可以开始编写基准测试了。这是我为另一个 Stack Overflow 问题编写的基准测试示例

于 2014-01-24T20:09:24.567 回答
9

以下是在撰写本文时使用最新版本的 Caliper caliper-1.0-beta2设置工作 Caliper 类的方法。据我所知,除了 Caliper 代码文件中的内联注释之外,没有记录此过程。

首先在pom.xml中安装 caliper-1.0-beta2或下载 jar 文件。然后制作一个像这样的文件:

import com.google.caliper.Benchmark;
import com.google.caliper.runner.CaliperMain;

public class DemoBenchmark {
  public static void main(String[] args) {
    CaliperMain.main(DemoBenchmark.class, args);
  }

  @Benchmark
  void timeStringBuilder(int reps) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < reps; i++) {
      sb.setLength(0);
      sb.append("hello world");
    }
  }
}

运行该文件,Caliper 将为您执行基准测试。

于 2016-12-23T06:17:00.630 回答
0

我已经在 Windows 上尝试了所有建议的解决方案,但是没有成功。

我总是遇到以下错误:

This selection yields 4 experiments.
ERROR: Trial failed to complete (its results will not be included in the run):
  The worker exited without producing data. It has likely crashed. Inspect C:\Users\Piotr\AppData\Local\Temp\1583760443321-0\trial-1.log to see any worker output.

我能够通过将@VmOptions注释添加到自定义基准类来解决它。

这是完整的配置:

@VmOptions("-XX:-TieredCompilation")
public class CaliperBenchmark {

    @BeforeExperiment
    void setUp() {
        // set up
    }

    @Benchmark
    void boxed() {
       // test
    }
}

马文:com.google.caliper caliper 1.0-beta-2 compile

主类:

public class Main {

    public static void main(String[] args) {
        CaliperMain.main(CaliperBenchmark.class, args);
    }
}

命令行:mvn exec:java -Dexec.mainClass="com.google.caliper.runner.CaliperMain" -Dexec.args="org.CaliperBenchmark"

于 2020-03-09T14:19:24.100 回答