Files
test-repo/benchmarks/string-concatenation.js
T
fisker Cheungandautofix-ci[bot] b87311a7cd Move cursor tracking out of the doc print buffer (#18202)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-11-04 03:54:35 +08:00

31 lines
733 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 concatentation (${size} strings)`,
assert: (result) => assert.equal(result, expected),
},
{
"Array#join()"() {
const result = [];
for (const string of strings) {
result.push(string);
}
return result.join("");
},
"string +="() {
let result = "";
for (const string of strings) {
result += string;
}
return result;
},
},
);
}