我已经使用 jsben.ch 比较了三个斐波那契数列算法,预期中第一个算法是最快的(它甚至获得了一个小奖章):
然而,我找不到代码块结果旁边的数字是什么意思?数字越高越好,但单位是什么?
ops/sec
,意思是每个测试可以在一秒内执行多少次。从代码(检查元素)来看,他们似乎只是通过 执行时间
或者他们所说的 runTime = a - s
来创建基准。
从代码中:
for (var u of e.model.codeBlocks) {
u.result.percent = 0,
yield e.$sleep(e.model.pausePerBlock);
var m = e.runTestForAmountOfTime(u, e.model.timeToRun);
u.result = {
runTime: m.runTime,
amountOfRounds: m.counter,
percent: 0
};
var p = m.timer - d;
e.state.app.testProgress = Math.round(100 / c * p),
e.state.app.testProgress > 100 && (e.state.app.testProgress = 100),
yield e.$sleep(e.model.pausePerBlock)
}
runTestForAmountofTime
:runTestForAmountOfTime(e, t) {
var o = "benchmark_" + e.id
, a = performance.now()
, s = performance.now()
, r = 0;
do {
this.iframe.contentWindow[o](arguments),
r++,
s = performance.now()
} while (s - a < t && !this.model.errorMessage);
return {
counter: r,
runTime: a - s, // I think that this is the point
timer: s
}
}