Tar*_*riq 14 javascript benchmark.js
我正在尝试使用Benchmark.js执行示例性能基准测试.这是我写的:
var Benchmark = require('benchmark');
var arr = []
benchmark = new Benchmark('testPerf',function(){
arr.push(1000);
},
{
delay: 0,
initCount: 1,
minSamples: 1000,
onComplete : function(){ console.log(this);},
onCycle: function(){}
});
benchmark.run();
Run Code Online (Sandbox Code Playgroud)
就像我们在JUnitBenchmarks中一样:
@BenchmarkOptions(clock = Clock.NANO_TIME, callgc = true, benchmarkRounds = 10, warmupRounds = 1)
Run Code Online (Sandbox Code Playgroud)
在这里,我还要声明benchmarkRounds并warmupRounds计入benchmarkjs.我认为warmupRounds地图initCount?以及如何设置确切的周期数/基准迭代次数?
或者,如果我们有一些其他好的JavaScript库可以处理它也会工作.
在JavaScript基准测试中使用固定迭代计数是有风险的:随着浏览器变得更快,我们最终可能获得零时间结果.
Benchmark.js不允许提前设置轮数/迭代次数.相反,它会一遍又一遍地运行测试,直到结果被认为是相当准确的.你应该查看Monsur Hossain的代码阅读.文章中的一些亮点:
Benchmark.prototype.cycles.Benchmark.prototype.stats.sample 是采样期间每个周期的结果数组.Benchmark.prototype.count 是采样期间的迭代次数.查看文档:
听起来你是对的
| 归档时间: |
|
| 查看次数: |
1298 次 |
| 最近记录: |