Skip to content

Conversation

@SuperchupuDev
Copy link
Contributor

Potential improvement found while working on #151. Tested with the following script:

const path = "/some/very/long/path/to/a/directory";
const root = "/some/very/long/path/";

console.time("slice");
for (let i = 0; i < 1_000_000; i++) {
  const result = path.slice(root.length);
}
console.timeEnd("slice");

console.time("replace");
for (let i = 0; i < 1_000_000; i++) {
  const result = path.replace(root, "");
}
console.timeEnd("replace");
slice: 5.921ms
replace: 24.304ms

@thecodrr thecodrr merged commit c16f510 into thecodrr:master Jun 29, 2025
8 checks passed
@SuperchupuDev SuperchupuDev deleted the perf/slice branch June 29, 2025 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants