Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

23 lines
672 B
JavaScript
Raw Permalink Normal View History

import assert from "node:assert/strict";
2025-11-04 04:56:54 +08:00
import { trimIndentation } from "../src/document/printer/trim-indentation.js";
import { runBenchmark } from "./utilities.js";
2025-11-04 04:56:54 +08:00
for (const size of [1, 1e1, 1e2]) {
const trimmed = "foo".repeat(size / 2);
const text = trimmed + " \t".repeat(size / 2);
await runBenchmark(
{
name: `Trim indentation (${size} spaces)`,
assert: (result) => assert.equal(result, trimmed),
},
{
2025-11-04 04:56:54 +08:00
loop: () => trimIndentation(text).text,
"RegExp (inline)": () => text.replace(/[ \t]*$/, ""),
"RegExp (stored)": (
(regexp) => () =>
text.replace(regexp, "")
)(/[ \t]*$/g),
},
);
}