使用Caliper时如何指定命令行?

发布于 2024-10-05 06:52:38 字数 297 浏览 3 评论 0原文

我发现 Google 的微型基准测试项目 Caliper 非常有趣,但文档仍然(除了一些示例)完全不存在。

我有两种不同的情况,我需要影响 JVM Caliper 启动的命令行:

  1. 我需要设置一些固定的(理想情况下在几个固定值之间交替) -D 参数
  2. 我需要指定一些固定的(理想情况下在几个固定值之间交替) 我看到了一些关于添加这样的

功能的讨论,但我无法断定它是否已添加,在这种情况下语法会变成什么?

一些示例或指向 Java 文档的指针(假设这在某处有记录)等将非常感激!

I find Google's micro benchmark project Caliper very interesting but the documentation is still (except some examples) quite non-existent.

I have two different cases where I need to influence the command line of the JVMs Caliper starts:

  1. I need to set some fixed (ideally alternated between a few fixed values) -D parameters
  2. I need to specify some fixed (ideally alternated between a few fixed values) JVM parameters

I saw some discussion about adding features like this but I could not conclude if it has been added or not and in that case what the syntax became?

Some example or pointers into Java doc (assuming this is at all documented somewhere) etc would be very much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

御守 2024-10-12 06:52:38

要使用命令行参数修复基准参数,请使用 -Dname=value。有一个特殊参数,名为benchmark;它的值是您的 time 方法的后缀。如果您想将参数限制为多个值,请用逗号分隔它们,如下所示:-Dname=value1,value2

要设置 JVM 参数,请使用 -Jname=flag1,flag2

例如,考虑此基准测试:

public class StringBuilderBenchmark extends SimpleBenchmark {

    @Param({"1", "10", "100"}) private int length;

    public void timeAppendBoolean(int reps) {
        for (int i = 0; i < reps; ++i) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < length; ++j) {
                sb.append(true);
            }
        }
    }

    public void timeAppendChar(int reps) {
        for (int i = 0; i < reps; ++i) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < length; ++j) {
                sb.append('c');
            }
        }
    }
}

要以长度 5 和 6 以及大堆和小堆运行此基准测试,请使用这些参数:

java -cp caliper-0.0.jar:build/classes/test \
    com.google.caliper.Runner examples.StringBuilderBenchmark \
    -Dlength=5,6 -Dbenchmark=AppendBoolean -Jmemory=-Xmx512M,-Xmx16M

这将产生以下结果:

 0% Scenario{vm=java, trial=0, benchmark=AppendBoolean, length=5, memory=-Xmx512M} 81.79 ns; σ=0.31 ns @ 3 trials
25% Scenario{vm=java, trial=0, benchmark=AppendBoolean, length=6, memory=-Xmx512M} 89.72 ns; σ=2.19 ns @ 10 trials
50% Scenario{vm=java, trial=0, benchmark=AppendBoolean, length=5, memory=-Xmx16M} 111.44 ns; σ=6.01 ns @ 10 trials
75% Scenario{vm=java, trial=0, benchmark=AppendBoolean, length=6, memory=-Xmx16M} 120.23 ns; σ=4.59 ns @ 10 trials

  memory length    ns logarithmic runtime
-Xmx512M      5  81.8 =
-Xmx512M      6  89.7 =======
 -Xmx16M      5 111.4 ========================
 -Xmx16M      6 120.2 =============================

vm: java
trial: 0
benchmark: AppendBoolean

To fix a benchmark parameter with a command line argument, use -Dname=value. There is one special parameter named benchmark; it's values are the suffixes to your time methods. If you'd like to limit a parameter to multiple values, separate them by commas like this: -Dname=value1,value2.

To set JVM parameters, use -Jname=flag1,flag2.

For example consider this benchmark:

public class StringBuilderBenchmark extends SimpleBenchmark {

    @Param({"1", "10", "100"}) private int length;

    public void timeAppendBoolean(int reps) {
        for (int i = 0; i < reps; ++i) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < length; ++j) {
                sb.append(true);
            }
        }
    }

    public void timeAppendChar(int reps) {
        for (int i = 0; i < reps; ++i) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < length; ++j) {
                sb.append('c');
            }
        }
    }
}

To run this benchmark with lengths 5 and 6, and large and small heaps, use these parameters:

java -cp caliper-0.0.jar:build/classes/test \
    com.google.caliper.Runner examples.StringBuilderBenchmark \
    -Dlength=5,6 -Dbenchmark=AppendBoolean -Jmemory=-Xmx512M,-Xmx16M

This yields the following:

 0% Scenario{vm=java, trial=0, benchmark=AppendBoolean, length=5, memory=-Xmx512M} 81.79 ns; σ=0.31 ns @ 3 trials
25% Scenario{vm=java, trial=0, benchmark=AppendBoolean, length=6, memory=-Xmx512M} 89.72 ns; σ=2.19 ns @ 10 trials
50% Scenario{vm=java, trial=0, benchmark=AppendBoolean, length=5, memory=-Xmx16M} 111.44 ns; σ=6.01 ns @ 10 trials
75% Scenario{vm=java, trial=0, benchmark=AppendBoolean, length=6, memory=-Xmx16M} 120.23 ns; σ=4.59 ns @ 10 trials

  memory length    ns logarithmic runtime
-Xmx512M      5  81.8 =
-Xmx512M      6  89.7 =======
 -Xmx16M      5 111.4 ========================
 -Xmx16M      6 120.2 =============================

vm: java
trial: 0
benchmark: AppendBoolean
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文