0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/es/defaultparams-bench.js
Bartosz Sosnowski ef8cc301fe benchmark: remove forced optimization from es
This removes all instances of %OptimizeFunctionOnNextCall from es
benchmarks

PR-URL: https://github.com/nodejs/node/pull/9615
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2017-03-06 16:31:58 +01:00

55 lines
969 B
JavaScript

'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
method: ['withoutdefaults', 'withdefaults'],
millions: [100]
});
function oldStyleDefaults(x, y) {
x = x || 1;
y = y || 2;
assert.strictEqual(x, 1);
assert.strictEqual(y, 2);
}
function defaultParams(x = 1, y = 2) {
assert.strictEqual(x, 1);
assert.strictEqual(y, 2);
}
function runOldStyleDefaults(n) {
var i = 0;
bench.start();
for (; i < n; i++)
oldStyleDefaults();
bench.end(n / 1e6);
}
function runDefaultParams(n) {
var i = 0;
bench.start();
for (; i < n; i++)
defaultParams();
bench.end(n / 1e6);
}
function main(conf) {
const n = +conf.millions * 1e6;
switch (conf.method) {
case 'withoutdefaults':
runOldStyleDefaults(n);
break;
case 'withdefaults':
runDefaultParams(n);
break;
default:
throw new Error('Unexpected method');
}
}