11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common.js'); 41cb0ef41Sopenharmony_ciconst util = require('util'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 71cb0ef41Sopenharmony_ci type: ['extend', 'assign'], 81cb0ef41Sopenharmony_ci n: [10e4], 91cb0ef41Sopenharmony_ci}); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cifunction main({ n, type }) { 121cb0ef41Sopenharmony_ci let fn; 131cb0ef41Sopenharmony_ci if (type === 'extend') { 141cb0ef41Sopenharmony_ci fn = util._extend; 151cb0ef41Sopenharmony_ci } else if (type === 'assign') { 161cb0ef41Sopenharmony_ci fn = Object.assign; 171cb0ef41Sopenharmony_ci } 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci // Force-optimize the method to test so that the benchmark doesn't 201cb0ef41Sopenharmony_ci // get disrupted by the optimizer kicking in halfway through. 211cb0ef41Sopenharmony_ci for (let i = 0; i < type.length * 10; i += 1) 221cb0ef41Sopenharmony_ci fn({}, process.env); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci const obj = new Proxy({}, { set: function(a, b, c) { return true; } }); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci bench.start(); 271cb0ef41Sopenharmony_ci for (let j = 0; j < n; j += 1) 281cb0ef41Sopenharmony_ci fn(obj, process.env); 291cb0ef41Sopenharmony_ci bench.end(n); 301cb0ef41Sopenharmony_ci} 31