Skip to content

Commit

Permalink
Create path-relative.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Feb 11, 2025
1 parent ff259c9 commit 8a47b78
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions bench/snippets/path-relative.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { posix } from "path";
import { bench, run } from "../runner.mjs";

const pathConfigurations = [
["", ""],
[".", "."],
["/foo/bar", "/foo/bar"],
["/foo/bar/baz", "/foo/bar"],
["/foo/bar", "/foo/bar/baz"],
["/foo/bar/baz", "/foo/bar/qux"],
["/foo/bar/baz", "/foo/bar/baz/qux"],
["/foo/bar/baz", "/foo/bar/baz/qux/quux"],
["/", "/foo"],
["/foo", "/"],
["foo/bar/baz", "foo/bar/qux"],
["../foo/bar", "../foo/baz"],
];

pathConfigurations.forEach(([from, to]) => {
bench(`relative(${JSON.stringify(from)}, ${JSON.stringify(to)})`, () => {
globalThis.abc = posix.relative(from, to);
});
});

await run();

0 comments on commit 8a47b78

Please sign in to comment.