11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst common = require('../common.js'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst configs = { 71cb0ef41Sopenharmony_ci n: [1e3], 81cb0ef41Sopenharmony_ci mode: ['Array', 'repeat'], 91cb0ef41Sopenharmony_ci encoding: ['ascii', 'utf8'], 101cb0ef41Sopenharmony_ci size: [1e1, 1e3, 1e6], 111cb0ef41Sopenharmony_ci}; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, configs); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cifunction main({ n, size, encoding, mode }) { 161cb0ef41Sopenharmony_ci const character = encoding === 'ascii' ? 'a' : '\ud83d\udc0e'; // '' 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci let str; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci switch (mode) { 211cb0ef41Sopenharmony_ci case 'Array': 221cb0ef41Sopenharmony_ci bench.start(); 231cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) 241cb0ef41Sopenharmony_ci str = new Array(size + 1).join(character); 251cb0ef41Sopenharmony_ci bench.end(n); 261cb0ef41Sopenharmony_ci break; 271cb0ef41Sopenharmony_ci case 'repeat': 281cb0ef41Sopenharmony_ci bench.start(); 291cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) 301cb0ef41Sopenharmony_ci str = character.repeat(size); 311cb0ef41Sopenharmony_ci bench.end(n); 321cb0ef41Sopenharmony_ci break; 331cb0ef41Sopenharmony_ci default: 341cb0ef41Sopenharmony_ci throw new Error(`Unexpected method "${mode}"`); 351cb0ef41Sopenharmony_ci } 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci assert.strictEqual([...str].length, size); 381cb0ef41Sopenharmony_ci} 39