mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
bb6125bac7
This reverts commit 7cfbc9f90f
.
PR-URL: https://github.com/nodejs/node/pull/31755
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
39 lines
835 B
JavaScript
39 lines
835 B
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
const common = require('../common.js');
|
|
|
|
const configs = {
|
|
n: [1e3],
|
|
mode: ['Array', 'repeat'],
|
|
encoding: ['ascii', 'utf8'],
|
|
size: [1e1, 1e3, 1e6],
|
|
};
|
|
|
|
const bench = common.createBenchmark(main, configs);
|
|
|
|
function main({ n, size, encoding, mode }) {
|
|
const character = encoding === 'ascii' ? 'a' : '\ud83d\udc0e'; // '🐎'
|
|
|
|
let str;
|
|
|
|
switch (mode) {
|
|
case 'Array':
|
|
bench.start();
|
|
for (let i = 0; i < n; i++)
|
|
str = new Array(size + 1).join(character);
|
|
bench.end(n);
|
|
break;
|
|
case 'repeat':
|
|
bench.start();
|
|
for (let i = 0; i < n; i++)
|
|
str = character.repeat(size);
|
|
bench.end(n);
|
|
break;
|
|
default:
|
|
throw new Error(`Unexpected method "${mode}"`);
|
|
}
|
|
|
|
assert.strictEqual([...str].length, size);
|
|
}
|