2016-06-10 04:10:10 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common.js');
|
|
|
|
const util = require('util');
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
|
|
type: ['extend', 'assign'],
|
|
|
|
n: [10e4]
|
|
|
|
});
|
|
|
|
|
2017-12-30 03:57:38 +01:00
|
|
|
function main({ n, type }) {
|
2016-06-10 04:10:10 +02:00
|
|
|
let fn;
|
2017-12-30 03:57:38 +01:00
|
|
|
if (type === 'extend') {
|
2016-06-10 04:10:10 +02:00
|
|
|
fn = util._extend;
|
2017-12-30 03:57:38 +01:00
|
|
|
} else if (type === 'assign') {
|
2016-06-10 04:10:10 +02:00
|
|
|
fn = Object.assign;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force-optimize the method to test so that the benchmark doesn't
|
|
|
|
// get disrupted by the optimizer kicking in halfway through.
|
2017-12-30 03:57:38 +01:00
|
|
|
for (var i = 0; i < type.length * 10; i += 1)
|
2016-06-10 04:10:10 +02:00
|
|
|
fn({}, process.env);
|
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const obj = new Proxy({}, { set: function(a, b, c) { return true; } });
|
2016-06-10 04:10:10 +02:00
|
|
|
|
|
|
|
bench.start();
|
|
|
|
for (var j = 0; j < n; j += 1)
|
|
|
|
fn(obj, process.env);
|
|
|
|
bench.end(n);
|
|
|
|
}
|