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  method: ['spread', 'assign', '_extend'],
81cb0ef41Sopenharmony_ci  count: [5, 10, 20],
91cb0ef41Sopenharmony_ci  n: [1e6],
101cb0ef41Sopenharmony_ci});
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cifunction main({ n, context, count, rest, method }) {
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci  const src = {};
151cb0ef41Sopenharmony_ci  for (let n = 0; n < count; n++)
161cb0ef41Sopenharmony_ci    src[`p${n}`] = n;
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  let obj;
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci  switch (method) {
211cb0ef41Sopenharmony_ci    case '_extend':
221cb0ef41Sopenharmony_ci      bench.start();
231cb0ef41Sopenharmony_ci      for (let i = 0; i < n; i++)
241cb0ef41Sopenharmony_ci        obj = util._extend({}, src);
251cb0ef41Sopenharmony_ci      bench.end(n);
261cb0ef41Sopenharmony_ci      break;
271cb0ef41Sopenharmony_ci    case 'assign':
281cb0ef41Sopenharmony_ci      bench.start();
291cb0ef41Sopenharmony_ci      for (let i = 0; i < n; i++)
301cb0ef41Sopenharmony_ci        obj = Object.assign({}, src);
311cb0ef41Sopenharmony_ci      bench.end(n);
321cb0ef41Sopenharmony_ci      break;
331cb0ef41Sopenharmony_ci    case 'spread':
341cb0ef41Sopenharmony_ci      bench.start();
351cb0ef41Sopenharmony_ci      for (let i = 0; i < n; i++)
361cb0ef41Sopenharmony_ci        obj = { ...src }; // eslint-disable-line no-unused-vars
371cb0ef41Sopenharmony_ci      bench.end(n);
381cb0ef41Sopenharmony_ci      break;
391cb0ef41Sopenharmony_ci    default:
401cb0ef41Sopenharmony_ci      throw new Error('Unexpected method');
411cb0ef41Sopenharmony_ci  }
421cb0ef41Sopenharmony_ci}
43