0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/benchmark/arrays/zero-int.js
Michaël Zasso eefdf452c3 benchmark: avoid TurboFan deopt in arrays bench
Something unidentified at the moment is causing the arrays benchmarks to
deopt when run with the TurboFan compiler. Refactor the test to use an
inner function that can be correctly optimized by TurboFan and
Crankshaft.

PR-URL: https://github.com/nodejs/node/pull/11894
Ref: https://github.com/nodejs/node/issues/11851#issuecomment-287106714
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2017-04-04 10:45:43 -07:00

40 lines
606 B
JavaScript

'use strict';
var common = require('../common.js');
var types = [
'Array',
'Buffer',
'Int8Array',
'Uint8Array',
'Int16Array',
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array'
];
var bench = common.createBenchmark(main, {
type: types,
n: [25]
});
function main(conf) {
var type = conf.type;
var clazz = global[type];
var n = +conf.n;
bench.start();
var arr = new clazz(n * 1e6);
for (var i = 0; i < 10; ++i) {
run();
}
bench.end(n);
function run() {
for (var j = 0, k = arr.length; j < k; ++j) {
arr[j] = 0;
}
}
}