11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci/* eslint-disable dot-notation */
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst common = require('../common.js');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, {
81cb0ef41Sopenharmony_ci  method: ['property', 'string', 'variable', 'symbol'],
91cb0ef41Sopenharmony_ci  n: [1e9],
101cb0ef41Sopenharmony_ci});
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cifunction runProperty(n) {
131cb0ef41Sopenharmony_ci  const object = {};
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  bench.start();
161cb0ef41Sopenharmony_ci  for (let i = 0; i < n; i++) {
171cb0ef41Sopenharmony_ci    object.p1 = 21;
181cb0ef41Sopenharmony_ci    object.p2 = 21;
191cb0ef41Sopenharmony_ci    object.p1 += object.p2;
201cb0ef41Sopenharmony_ci  }
211cb0ef41Sopenharmony_ci  bench.end(n);
221cb0ef41Sopenharmony_ci}
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_cifunction runString(n) {
251cb0ef41Sopenharmony_ci  const object = {};
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci  bench.start();
281cb0ef41Sopenharmony_ci  for (let i = 0; i < n; i++) {
291cb0ef41Sopenharmony_ci    object['p1'] = 21;
301cb0ef41Sopenharmony_ci    object['p2'] = 21;
311cb0ef41Sopenharmony_ci    object['p1'] += object['p2'];
321cb0ef41Sopenharmony_ci  }
331cb0ef41Sopenharmony_ci  bench.end(n);
341cb0ef41Sopenharmony_ci}
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_cifunction runVariable(n) {
371cb0ef41Sopenharmony_ci  const object = {};
381cb0ef41Sopenharmony_ci  const var1 = 'p1';
391cb0ef41Sopenharmony_ci  const var2 = 'p2';
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  bench.start();
421cb0ef41Sopenharmony_ci  for (let i = 0; i < n; i++) {
431cb0ef41Sopenharmony_ci    object[var1] = 21;
441cb0ef41Sopenharmony_ci    object[var2] = 21;
451cb0ef41Sopenharmony_ci    object[var1] += object[var2];
461cb0ef41Sopenharmony_ci  }
471cb0ef41Sopenharmony_ci  bench.end(n);
481cb0ef41Sopenharmony_ci}
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_cifunction runSymbol(n) {
511cb0ef41Sopenharmony_ci  const object = {};
521cb0ef41Sopenharmony_ci  const symbol1 = Symbol('p1');
531cb0ef41Sopenharmony_ci  const symbol2 = Symbol('p2');
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci  bench.start();
561cb0ef41Sopenharmony_ci  for (let i = 0; i < n; i++) {
571cb0ef41Sopenharmony_ci    object[symbol1] = 21;
581cb0ef41Sopenharmony_ci    object[symbol2] = 21;
591cb0ef41Sopenharmony_ci    object[symbol1] += object[symbol2];
601cb0ef41Sopenharmony_ci  }
611cb0ef41Sopenharmony_ci  bench.end(n);
621cb0ef41Sopenharmony_ci}
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_cifunction main({ n, method }) {
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci  switch (method) {
671cb0ef41Sopenharmony_ci    case 'property':
681cb0ef41Sopenharmony_ci      runProperty(n);
691cb0ef41Sopenharmony_ci      break;
701cb0ef41Sopenharmony_ci    case 'string':
711cb0ef41Sopenharmony_ci      runString(n);
721cb0ef41Sopenharmony_ci      break;
731cb0ef41Sopenharmony_ci    case 'variable':
741cb0ef41Sopenharmony_ci      runVariable(n);
751cb0ef41Sopenharmony_ci      break;
761cb0ef41Sopenharmony_ci    case 'symbol':
771cb0ef41Sopenharmony_ci      runSymbol(n);
781cb0ef41Sopenharmony_ci      break;
791cb0ef41Sopenharmony_ci    default:
801cb0ef41Sopenharmony_ci      throw new Error(`Unexpected method "${method}"`);
811cb0ef41Sopenharmony_ci  }
821cb0ef41Sopenharmony_ci}
83