如何显示/读取结果(操作数/秒)? [英] How to display/read results (ops/sec)?

查看:155
本文介绍了如何显示/读取结果(操作数/秒)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够成功创建并运行基准套件,但是不确定如何获取每个输出的基准值,onComplete中的this.filter('fastest').pluck('name')为我提供了最快操作的名称,但是我想使用ops/sec测试套件中每个功能的值.怎么得到的?

I am able to successfully create and run benchmark suite, but not sure how to get the benchmark values of each output, this.filter('fastest').pluck('name') in onComplete gives me the name of the fastest operation, but I want the ops/sec value of each function in the test suite. how to get that?

推荐答案

在您的onComplete回调中,您可以通过this关键字(它将引用当前的

In your onComplete callback you can access your benchmarks through this keyword (which will reference to the current BenchmarkSuite object) like this:

var bench1 = this[0];
var bench2 = this[1];
...
var benchN = this[N-1];

每个bench基准的实例.因此,您可以获得所需的任何信息(请参阅 Benchmark.prototype ).要获取ops/sec值,请使用基准的 .hz 属性.一个更好理解的小例子:

Each bench is instance of Benchmark. So you can get any information you want (see Benchmark.prototype ). To get ops/sec value use .hz property of benchmark. A small example for better understanding:

new Benchmark.Suite()
.add('test1', function() {
    // some code
})
.add('test2', function() {
    // some code
})
.on('complete', function() {
    var benchTest1 = this[0]; // gets benchmark for test1
    var benchTest2 = this[1]; // gets benchmark for test2

    console.log(benchTest1.hz); // ops/sec
    // benchmark info in format: 
    // test2 x 1,706,681 ops/sec ±1.18% (92 runs sampled)
    console.log(benchTest2.toString()); 

    console.log('Fastest is ' + this.filter('fastest').pluck('name'));
})
.run();

这篇关于如何显示/读取结果(操作数/秒)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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