11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common.js'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 61cb0ef41Sopenharmony_ci method: ['normal', 'destructureObject'], 71cb0ef41Sopenharmony_ci n: [1e8], 81cb0ef41Sopenharmony_ci}); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cifunction runNormal(n) { 111cb0ef41Sopenharmony_ci const o = { x: 0, y: 1 }; 121cb0ef41Sopenharmony_ci bench.start(); 131cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) { 141cb0ef41Sopenharmony_ci /* eslint-disable no-unused-vars */ 151cb0ef41Sopenharmony_ci const x = o.x; 161cb0ef41Sopenharmony_ci const y = o.y; 171cb0ef41Sopenharmony_ci const r = o.r || 2; 181cb0ef41Sopenharmony_ci /* eslint-enable no-unused-vars */ 191cb0ef41Sopenharmony_ci } 201cb0ef41Sopenharmony_ci bench.end(n); 211cb0ef41Sopenharmony_ci} 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_cifunction runDestructured(n) { 241cb0ef41Sopenharmony_ci const o = { x: 0, y: 1 }; 251cb0ef41Sopenharmony_ci bench.start(); 261cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) { 271cb0ef41Sopenharmony_ci /* eslint-disable no-unused-vars */ 281cb0ef41Sopenharmony_ci const { x, y, r = 2 } = o; 291cb0ef41Sopenharmony_ci /* eslint-enable no-unused-vars */ 301cb0ef41Sopenharmony_ci } 311cb0ef41Sopenharmony_ci bench.end(n); 321cb0ef41Sopenharmony_ci} 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_cifunction main({ n, method }) { 351cb0ef41Sopenharmony_ci switch (method) { 361cb0ef41Sopenharmony_ci case 'normal': 371cb0ef41Sopenharmony_ci runNormal(n); 381cb0ef41Sopenharmony_ci break; 391cb0ef41Sopenharmony_ci case 'destructureObject': 401cb0ef41Sopenharmony_ci runDestructured(n); 411cb0ef41Sopenharmony_ci break; 421cb0ef41Sopenharmony_ci default: 431cb0ef41Sopenharmony_ci throw new Error(`Unexpected method "${method}"`); 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci} 46