• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common.js');
4const util = require('util');
5
6const bench = common.createBenchmark(main, {
7  type: ['extend', 'assign'],
8  n: [10e4],
9});
10
11function main({ n, type }) {
12  let fn;
13  if (type === 'extend') {
14    fn = util._extend;
15  } else if (type === 'assign') {
16    fn = Object.assign;
17  }
18
19  // Force-optimize the method to test so that the benchmark doesn't
20  // get disrupted by the optimizer kicking in halfway through.
21  for (let i = 0; i < type.length * 10; i += 1)
22    fn({}, process.env);
23
24  const obj = new Proxy({}, { set: function(a, b, c) { return true; } });
25
26  bench.start();
27  for (let j = 0; j < n; j += 1)
28    fn(obj, process.env);
29  bench.end(n);
30}
31