11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common.js'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst configs = { 61cb0ef41Sopenharmony_ci n: [1e3], 71cb0ef41Sopenharmony_ci mode: [ 81cb0ef41Sopenharmony_ci 'multi-concat', 91cb0ef41Sopenharmony_ci 'multi-join', 101cb0ef41Sopenharmony_ci 'multi-template', 111cb0ef41Sopenharmony_ci 'to-string-string', 121cb0ef41Sopenharmony_ci 'to-string-concat', 131cb0ef41Sopenharmony_ci 'to-string-template', 141cb0ef41Sopenharmony_ci ], 151cb0ef41Sopenharmony_ci}; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, configs); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_cifunction main({ n, mode }) { 201cb0ef41Sopenharmony_ci const str = 'abc'; 211cb0ef41Sopenharmony_ci const num = 123; 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci let string; 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci switch (mode) { 261cb0ef41Sopenharmony_ci case 'multi-concat': 271cb0ef41Sopenharmony_ci bench.start(); 281cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) 291cb0ef41Sopenharmony_ci string = '...' + str + ', ' + num + ', ' + str + ', ' + num + '.'; 301cb0ef41Sopenharmony_ci bench.end(n); 311cb0ef41Sopenharmony_ci break; 321cb0ef41Sopenharmony_ci case 'multi-join': 331cb0ef41Sopenharmony_ci bench.start(); 341cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) 351cb0ef41Sopenharmony_ci string = ['...', str, ', ', num, ', ', str, ', ', num, '.'].join(''); 361cb0ef41Sopenharmony_ci bench.end(n); 371cb0ef41Sopenharmony_ci break; 381cb0ef41Sopenharmony_ci case 'multi-template': 391cb0ef41Sopenharmony_ci bench.start(); 401cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) 411cb0ef41Sopenharmony_ci string = `...${str}, ${num}, ${str}, ${num}.`; 421cb0ef41Sopenharmony_ci bench.end(n); 431cb0ef41Sopenharmony_ci break; 441cb0ef41Sopenharmony_ci case 'to-string-string': 451cb0ef41Sopenharmony_ci bench.start(); 461cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) 471cb0ef41Sopenharmony_ci string = String(num); 481cb0ef41Sopenharmony_ci bench.end(n); 491cb0ef41Sopenharmony_ci break; 501cb0ef41Sopenharmony_ci case 'to-string-concat': 511cb0ef41Sopenharmony_ci bench.start(); 521cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) 531cb0ef41Sopenharmony_ci string = '' + num; 541cb0ef41Sopenharmony_ci bench.end(n); 551cb0ef41Sopenharmony_ci break; 561cb0ef41Sopenharmony_ci case 'to-string-template': 571cb0ef41Sopenharmony_ci bench.start(); 581cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) 591cb0ef41Sopenharmony_ci string = `${num}`; 601cb0ef41Sopenharmony_ci bench.end(n); 611cb0ef41Sopenharmony_ci break; 621cb0ef41Sopenharmony_ci default: 631cb0ef41Sopenharmony_ci throw new Error(`Unexpected method "${mode}"`); 641cb0ef41Sopenharmony_ci } 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci return string; 671cb0ef41Sopenharmony_ci} 68