2025-11-04 03:54:35 +08:00
|
|
|
import assert from "node:assert/strict";
|
2025-11-04 04:56:54 +08:00
|
|
|
import { trimIndentation } from "../src/document/printer/trim-indentation.js";
|
2025-11-04 03:54:35 +08:00
|
|
|
import { runBenchmark } from "./utilities.js";
|
|
|
|
|
|
2025-11-04 04:56:54 +08:00
|
|
|
for (const size of [1, 1e1, 1e2]) {
|
2025-11-04 03:54:35 +08:00
|
|
|
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,
|
2025-12-21 23:44:08 +08:00
|
|
|
"RegExp (inline)": () => text.replace(/[ \t]*$/, ""),
|
2025-11-04 03:54:35 +08:00
|
|
|
"RegExp (stored)": (
|
|
|
|
|
(regexp) => () =>
|
|
|
|
|
text.replace(regexp, "")
|
2025-12-21 23:44:08 +08:00
|
|
|
)(/[ \t]*$/g),
|
2025-11-04 03:54:35 +08:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|