Files
test-repo/benchmarks/string-concatenation.js
7e4be2e1eb Update eslint-plugin-unicorn to v66 (#19356)
Co-authored-by: fisker <lionkay@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-06-16 01:33:59 +08:00

32 lines
790 B
JavaScript

import assert from "node:assert/strict";
import { runBenchmark } from "./utilities.js";
for (const size of [1e1, 1e2, 1e3, 1e4, 1e5]) {
const strings = Array.from({ length: size }, () => "_");
const expected = strings.join("");
await runBenchmark(
{
name: `String concatenation (${size} strings)`,
assert: (result) => assert.equal(result, expected),
},
{
"Array#join()"() {
const result = [];
// eslint-disable-next-line unicorn/prefer-spread
for (const string of strings) {
result.push(string);
}
return result.join("");
},
"string +="() {
let result = "";
for (const string of strings) {
result += string;
}
return result;
},
},
);
}