Files
test-repo/benchmarks/trim-indentation.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

26 lines
812 B
JavaScript

import assert from "node:assert/strict";
import { trimTrailingIndentation } from "../src/document/printer/trim-indentation.js";
import { runBenchmark } from "./utilities.js";
for (const size of [1, 1e1, 1e2, 1e3]) {
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),
},
{
loop: () => trimTrailingIndentation(text),
"RegExp (inline)": () => text.replace(/[ \t]*$/u, ""),
"RegExp (stored)": (
(regexp) => () =>
text.replace(regexp, "")
)(/[ \t]*$/gu),
// eslint-disable-next-line require-unicode-regexp
"RegExp (no `u` flag)": () => text.replace(/[ \t]*$/, ""),
},
);
}