aboutsummaryrefslogtreecommitdiff
path: root/bench/scanner
diff options
context:
space:
mode:
Diffstat (limited to 'bench/scanner')
-rwxr-xr-xbench/scanner/bun.lockbbin0 -> 6186 bytes
-rw-r--r--bench/scanner/package.json6
-rw-r--r--bench/scanner/remix-route.ts15
-rw-r--r--bench/scanner/scan-imports-only.js15
-rw-r--r--bench/scanner/scan.bun.js21
-rw-r--r--bench/scanner/scan.node-esbuild.mjs42
6 files changed, 99 insertions, 0 deletions
diff --git a/bench/scanner/bun.lockb b/bench/scanner/bun.lockb
new file mode 100755
index 000000000..90bb78996
--- /dev/null
+++ b/bench/scanner/bun.lockb
Binary files differ
diff --git a/bench/scanner/package.json b/bench/scanner/package.json
new file mode 100644
index 000000000..7bb4e8990
--- /dev/null
+++ b/bench/scanner/package.json
@@ -0,0 +1,6 @@
+{
+ "name": "scan",
+ "dependencies": {
+ "esbuild": "^0.14.11"
+ }
+} \ No newline at end of file
diff --git a/bench/scanner/remix-route.ts b/bench/scanner/remix-route.ts
new file mode 100644
index 000000000..dbacf3a4c
--- /dev/null
+++ b/bench/scanner/remix-route.ts
@@ -0,0 +1,15 @@
+import { useParams } from "remix";
+import type { LoaderFunction, ActionFunction } from "remix";
+
+export const loader: LoaderFunction = async ({ params }) => {
+ console.log(params.postId);
+};
+
+export const action: ActionFunction = async ({ params }) => {
+ console.log(params.postId);
+};
+
+export default function PostRoute() {
+ const params = useParams();
+ console.log(params.postId);
+}
diff --git a/bench/scanner/scan-imports-only.js b/bench/scanner/scan-imports-only.js
new file mode 100644
index 000000000..53222d57c
--- /dev/null
+++ b/bench/scanner/scan-imports-only.js
@@ -0,0 +1,15 @@
+import { readFileSync } from "fs";
+const fixture = ["action", "default", "loader"];
+
+const transpiler = new Bun.Transpiler({
+ loader: "ts",
+});
+
+console.time("Get exports");
+const ITERATIONS = parseInt(process.env.ITERATIONS || "1") || 1;
+for (let i = 0; i < ITERATIONS; i++) {
+ const imports = transpiler.scanImports(
+ readFileSync("remix-route.ts", "utf8")
+ );
+}
+console.timeEnd("Get exports");
diff --git a/bench/scanner/scan.bun.js b/bench/scanner/scan.bun.js
new file mode 100644
index 000000000..eb2b09452
--- /dev/null
+++ b/bench/scanner/scan.bun.js
@@ -0,0 +1,21 @@
+import { readFileSync } from "fs";
+const fixture = ["action", "default", "loader"];
+const ITERATIONS = parseInt(process.env.ITERATIONS || "1") || 1;
+
+const transpiler = new Bun.Transpiler({
+ loader: "ts",
+});
+
+console.time("Get exports");
+const file = readFileSync("remix-route.ts", "utf8");
+for (let i = 0; i < ITERATIONS; i++) {
+ const { imports, exports } = transpiler.scan(file);
+
+ for (let j = 0; j < fixture.length; j++) {
+ if (fixture[j] !== exports[j]) {
+ throw new Error("Mismatch");
+ }
+ }
+}
+
+console.timeEnd("Get exports");
diff --git a/bench/scanner/scan.node-esbuild.mjs b/bench/scanner/scan.node-esbuild.mjs
new file mode 100644
index 000000000..1a7fa79d8
--- /dev/null
+++ b/bench/scanner/scan.node-esbuild.mjs
@@ -0,0 +1,42 @@
+import { build, buildSync } from "esbuild";
+import { readFileSync } from "fs";
+const fixture = ["action", "default", "loader"];
+const ITERATIONS = parseInt(process.env.ITERATIONS || "1") || 1;
+
+const opts = {
+ metafile: true,
+ format: "esm",
+ platform: "neutral",
+ write: false,
+ logLevel: "silent",
+ stdin: {
+ contents: readFileSync("remix-route.ts", "utf8"),
+ loader: "ts",
+ sourcefile: "remix-route.js",
+ },
+};
+
+const getExports = ({ metafile }) => {
+ for (let i = 0; i < fixture.length; i++) {
+ if (fixture[i] !== metafile.outputs["stdin.js"].exports[i]) {
+ throw new Error("Mismatch");
+ }
+ }
+};
+
+console.time("Get exports");
+
+if (!process.env.SYNC) {
+ var promises = new Array(ITERATIONS);
+ for (let i = 0; i < ITERATIONS; i++) {
+ promises[i] = build(opts).then(getExports);
+ }
+
+ await Promise.all(promises);
+} else {
+ for (let i = 0; i < ITERATIONS; i++) {
+ getExports(buildSync(opts));
+ }
+}
+
+console.timeEnd("Get exports");