如何在没有Maven的情况下使用Caliper基准Beta快照? [英] How to use Caliper benchmark beta snapshot without maven?

查看:96
本文介绍了如何在没有Maven的情况下使用Caliper基准Beta快照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人要求我使用Google的Caliper项目创建一些微基准.我非常想使用最新Beta快照的注释功能,但是除了一些小示例之外,我还很难找到有关如何实际运行该事物的良好文档.新的Maven集成功能,我也被要求不要使用.

I have been asked to use Google's Caliper project to create a few microbenchmarks. I would very much like to use the annotation features of the newest beta snapshot, but aside from a few small examples I am having trouble finding good documentation on how to actually run the thing... There is a video tutorial up which instructs users on the new maven integration feature, which I was also asked NOT to use.

现在,我只是从他们的一个例子中剥离了一个小例子,并用我从另一个SO问题中收集到的一些其他信息进行了修改:

Right now I just have a small example stripped from one of theirs, modified with some other information I gleaned from another SO question:

public class Benchmarks {

    public class Test {
        @Param int size; // set automatically by framework

        private int[] array; // set by us, in setUp()

        @BeforeExperiment void setUp() {
          // @Param values are guaranteed to have been injected by now
          array = new int[size];
        }

        @Benchmark int timeArrayIteration(int reps) {
            int dummy = 0;
            for (int i = 0; i < reps; i++) {
                for (int doNotIgnoreMe : array) {
                    dummy += doNotIgnoreMe;
                }
            }
          return dummy;
        }

    }

    //(Questionable practice here?)
    public static void main (String args[]) {
        CaliperMain.main(Test.class, args); 
    }

}

运行它会提示我我没有设置默认大小.我在寻找应该放置的位置时遇到了麻烦.

Running it gives me the message that I did not set a default value for size. I am having trouble tracking down where I should be putting it.

通过注释掉@Param行并为setUp中的数组声明赋予硬值来完全删除大小",只会导致它决定没有实验可做",我想这是有道理的.

Removing "size" entirely by commenting out the @Param line and giving a hard value to the array declaration in setUp just leads to it deciding that there are "No Experiments to be done," which makes sense, I suppose.

如果有任何最新的资源或教程可以指出我做错了(老实说,可能很多),我将非常感激.

If there are any up-to-date resources or tutorials that could point out what I am doing wrong (probably a whole lot, honestly) I would be very appreciative.

我已根据一些建议对此进行了更新:

I have updated to this as per some advice:

public class Benchmarks {
      @Param({"1", "10", "1000"}) int size; // set automatically by framework

  private int[] array; // set by us, in setUp()

  @BeforeExperiment void setUp() {
    // @Param values are guaranteed to have been injected by now
    array = new int[size];
  }

  @Benchmark int timeArrayIteration(int reps) {
    int dummy = 0;
    for (int i = 0; i < reps; i++) {
      for (int doNotIgnoreMe : array) {
        dummy += doNotIgnoreMe;
      }
    }
    return dummy;
  }
}

我正在运行Beta快照,并将Benchmarks类作为参数传递.我收到以下信息:

I am running through the beta snapshot and passing in the Benchmarks class as an argument. I receive the following:

Experiment selection: 
  Instruments:   []
  User parameters:   {size=[1, 10, 1000]}
  Virtual machines:  [default]
  Selection type:    Full cartesian product

There were no experiments to be performed for the class Benchmarks using the instruments [allocation, runtime]

似乎没有检测到任何乐器.我没有传递任何信息,正如在文档中提到的那样,它只使用默认分配,运行时(这对我而言很好).

It doesn't seem to be detecting any Instruments. I am not passing any in, as it's mentioned in the documentation that it simply uses default allocation, runtime (which is fine for my purposes).

双重发现了这个问题,愚蠢的错误.我确认后将进行快速撰写.

DOUBLE Found that problem, stupid mistake. Will do a quick write-up once I confirm it.

推荐答案

运行它会提示我我没有为尺寸设置默认值.

Running it gives me the message that I did not set a default value for size.

这很简单:

@Param({"1", "10", "1000"}) int size;


通过注释掉@Param行并为setUp中的数组声明赋予硬值来完全删除大小",只会导致它决定没有实验可以完成",我想这是有道理的./p>

Removing "size" entirely by commenting out the @Param line and giving a hard value to the array declaration in setUp just leads to it deciding that there are "No Experiments to be done," which makes sense, I suppose.

不,不是.在没有任何参数的情况下,每个基准测试方法都必须运行一次. 请参阅其他答案以获取解决方案.

No, it doesn't. Without any params, each benchmark method is to be run exactly once. See the other answer for the solution.

例如,在@Param上有很多Javadoc.实际上,变化不大.注释已替换了约定(现在您不需要time前缀),参数保持不变,安装程序使用注释而不是继承.

There's a quite some Javadoc, e.g., on @Param. Actually, not so much has changed. Annotations have replaced conventions (now you don't need the time prefix), params stayed the same, setup uses an annotation instead of inheritance.

这篇关于如何在没有Maven的情况下使用Caliper基准Beta快照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆