mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
6abb06f821
To copy the values of all enumerable own properties from- a source object to a target object, node still use- `util._extend`, though newer standard `Object.assign` is available. This is because `util._extend` is found to be faster than `Object.assign`. This benchmark test is to keep track of how performance compare. PR-URL: https://github.com/nodejs/node/pull/7255 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
41 lines
986 B
JavaScript
41 lines
986 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
const util = require('util');
|
|
const v8 = require('v8');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
type: ['extend', 'assign'],
|
|
n: [10e4]
|
|
});
|
|
|
|
function main(conf) {
|
|
let fn;
|
|
const n = conf.n | 0;
|
|
let v8command;
|
|
|
|
if (conf.type === 'extend') {
|
|
fn = util._extend;
|
|
v8command = '%OptimizeFunctionOnNextCall(util._extend)';
|
|
} else if (conf.type === 'assign') {
|
|
fn = Object.assign;
|
|
// Object.assign is built-in, cannot be optimized
|
|
v8command = '';
|
|
}
|
|
|
|
// Force-optimize the method to test so that the benchmark doesn't
|
|
// get disrupted by the optimizer kicking in halfway through.
|
|
for (var i = 0; i < conf.type.length * 10; i += 1)
|
|
fn({}, process.env);
|
|
|
|
v8.setFlagsFromString('--allow_natives_syntax');
|
|
eval(v8command);
|
|
|
|
var obj = new Proxy({}, { set: function(a, b, c) { return true; } });
|
|
|
|
bench.start();
|
|
for (var j = 0; j < n; j += 1)
|
|
fn(obj, process.env);
|
|
bench.end(n);
|
|
}
|