Skip to content

Commit

Permalink
Update benchmarks to use ESM (#3655)
Browse files Browse the repository at this point in the history
* Update benchmarks to ESM

* Undo packagejson changes
  • Loading branch information
colinhacks authored Jul 19, 2024
1 parent 349932d commit 46423ba
Show file tree
Hide file tree
Showing 25 changed files with 71 additions and 145 deletions.
4 changes: 2 additions & 2 deletions benchmarks/benchUtil.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as zNew from "../packages/zod/dist/commonjs/index.js";
import * as zOld from "./node_modules/zod/dist/commonjs/index.js";
import * as zOld from "zod";
import * as zNew from "../packages/zod/src/index.js";

export function makeSchema<T>(factory: (z: typeof zNew) => T) {
return {
Expand Down
8 changes: 1 addition & 7 deletions benchmarks/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,4 @@ const bench = metabench("z.boolean().parse", {
},
});

export default async function run() {
await bench.run();
}

if (require.main === module) {
run();
}
await bench.run();
8 changes: 1 addition & 7 deletions benchmarks/datetime-regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,4 @@ bench
return false;
});

export default async function run() {
await bench.run();
}

if (require.main === module) {
run();
}
await bench.run();
8 changes: 1 addition & 7 deletions benchmarks/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,4 @@ const bench = metabench("z.string().datetime().parse", {
},
});

export default async function run() {
await bench.run();
}

if (require.main === module) {
run();
}
await bench.run();
8 changes: 1 addition & 7 deletions benchmarks/discriminated-union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,4 @@ const bench = metabench("z.disriminatedUnion().parse")
zod4.parse(DATA);
});

export default async function run() {
await bench.run();
}

if (require.main === module) {
run();
}
await bench.run();
4 changes: 3 additions & 1 deletion benchmarks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { execa } from "execa";
const $ = execa({ stdout: "inherit", stderr: "inherit" });

async function run() {
console.log(process.argv[2].split(","));
const files = process.argv[2]
.split(",")
.map((file) => require.resolve(`./${file}`));
.map((file) => import.meta.resolve(`./${file}`).replace("file://", ""));

for (const file of files) {
console.log(`Running ${file}`);
await $`pnpm tsx ${file}`;
}
}
Expand Down
8 changes: 1 addition & 7 deletions benchmarks/instanceof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,4 @@ const bench = metabench("instanceof")
for (const _ of DATA) nullChainCheckTag(_);
});

export default async function run() {
await bench.run();
}

if (require.main === module) {
run();
}
await bench.run();
8 changes: 1 addition & 7 deletions benchmarks/ipv4-regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,4 @@ const bench = metabench("ipv4 regex")
return ipv4RegexI.test(DATA);
});

export default async function run() {
await bench.run();
}

if (require.main === module) {
run();
}
await bench.run();
8 changes: 1 addition & 7 deletions benchmarks/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,4 @@ const bench = metabench("z.number().parse", {
},
});

export default async function run() {
await bench.run();
}

if (require.main === module) {
run();
}
await bench.run();
8 changes: 2 additions & 6 deletions benchmarks/object-async.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { metabench } from "./metabench.js";
import { DATA, zod3, zod4 } from "./object-old.js";
import { DATA, zod3, zod4 } from "./object-setup.js";

const bench = metabench("small: z.object().parseAsync", {
async zod3() {
Expand All @@ -10,8 +10,4 @@ const bench = metabench("small: z.object().parseAsync", {
},
});

export default async function run() {
await bench.run();
}

if (require.main === module) run();
await bench.run();
8 changes: 1 addition & 7 deletions benchmarks/object-creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@ const bench = metabench("object creation")
obj.value;
});

export default async function run() {
await bench.run();
}

if (require.main === module) {
run();
}
await bench.run();
8 changes: 2 additions & 6 deletions benchmarks/object-fail.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { metabench } from "./metabench.js";
import { DATA, zod3, zod4 } from "./object-old.js";
import { DATA, zod3, zod4 } from "./object-setup.js";

const bench = metabench("small: z.object().safeParseAsync", {
zod3() {
Expand All @@ -10,8 +10,4 @@ const bench = metabench("small: z.object().safeParseAsync", {
},
});

export default async function run() {
await bench.run();
}

if (require.main === module) run();
await bench.run();
6 changes: 1 addition & 5 deletions benchmarks/object-moltar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,4 @@ const bench = metabench("small: z.object().safeParseAsync", {
},
});

export default async function run() {
await bench.run();
}

if (require.main === module) run();
await bench.run();
8 changes: 2 additions & 6 deletions benchmarks/object-safe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { metabench } from "./metabench.js";
import { DATA, zod3, zod4 } from "./object-old.js";
import { DATA, zod3, zod4 } from "./object-setup.js";

const bench = metabench("small: z.object().safeParse", {
zod3() {
Expand All @@ -10,8 +10,4 @@ const bench = metabench("small: z.object().safeParse", {
},
});

export default async function run() {
await bench.run();
}

if (require.main === module) run();
await bench.run();
8 changes: 2 additions & 6 deletions benchmarks/object-safeasync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { metabench } from "./metabench.js";
import { DATA, zod3, zod4 } from "./object-old.js";
import { DATA, zod3, zod4 } from "./object-setup.js";

const bench = metabench("small: z.object().safeParseAsync", {
async zod3() {
Expand All @@ -10,8 +10,4 @@ const bench = metabench("small: z.object().safeParseAsync", {
},
});

export default async function run() {
await bench.run();
}

if (require.main === module) run();
await bench.run();
34 changes: 14 additions & 20 deletions benchmarks/object-old.ts → benchmarks/object-setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeData, makeSchema } from "./benchUtil.js";
import { metabench } from "./metabench.js";
// import { metabench } from "./metabench.js";

export const { zod3, zod4 } = makeSchema((z) =>
z.object({
Expand All @@ -19,23 +19,17 @@ export var DATA: any[] = makeData(1000, () => {
});
});

const bench = metabench("small: z.object().parse", {
zod3() {
for (const d of DATA) {
zod3.parse(d);
}
},
zod4() {
for (const d of DATA) {
zod4.parse(d);
}
},
});

export default async function run() {
await bench.run();
}
// const bench = metabench("small: z.object().parse", {
// zod3() {
// for (const d of DATA) {
// zod3.parse(d);
// }
// },
// zod4() {
// for (const d of DATA) {
// zod4.parse(d);
// }
// },
// });

if (require.main === module) {
run();
}
// await bench.run();
6 changes: 1 addition & 5 deletions benchmarks/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,4 @@ const bench = zodbench({
},
});

export default bench.run;

if (require.main === module) {
bench.run();
}
await bench.run();
2 changes: 1 addition & 1 deletion benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"type": "module",
"name": "zod-benchmarks",
"devDependencies": {
"zod": "3.23.8"
"zod": "3.23.7"
}
}
8 changes: 1 addition & 7 deletions benchmarks/string-old.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,4 @@ const bench = metabench("z.string().parse", {
},
});

export default async function run() {
await bench.run();
}

if (require.main === module) {
run();
}
await bench.run();
8 changes: 1 addition & 7 deletions benchmarks/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@ const bench = zodbench({
},
});

export default async function run() {
await bench.run();
}

if (require.main === module) {
run();
}
await bench.run();
8 changes: 1 addition & 7 deletions benchmarks/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,4 @@ const bench = metabench("z.union().parse")
zod4.parse(DATA);
});

export default async function run() {
await bench.run();
}

if (require.main === module) {
run();
}
await bench.run();
2 changes: 1 addition & 1 deletion benchmarks/zodbench.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type z from "../packages/zod/dist/commonjs/index.js";
import type z from "../packages/zod/src/index.js";
import { makeSchema } from "./benchUtil.js";
import { metabench } from "./metabench.js";

Expand Down
14 changes: 11 additions & 3 deletions packages/effect-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
"type": "module",
"version": "0.1.0",
"author": "Colin McDonnell <zod@colinhacks.com>",
"files": ["src", "dist"],
"files": [
"src",
"dist"
],
"funding": "https://github.com/sponsors/colinhacks",
"homepage": "https://zod.dev",
"keywords": ["typescript", "schema", "validation", "type", "inference"],
"keywords": [
"typescript",
"schema",
"validation",
"type",
"inference"
],
"license": "MIT",
"sideEffects": false,
"main": "./dist/commonjs/index.js",
Expand All @@ -16,7 +25,6 @@
"./package.json": "./package.json",
".": {
"import": {
"@zod/source": "./src/index.ts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
Expand Down
15 changes: 11 additions & 4 deletions packages/zod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@
"version": "3.23.8",
"author": "Colin McDonnell <zod@colinhacks.com>",
"description": "TypeScript-first schema declaration and validation library with static type inference",
"files": ["src", "dist"],
"files": [
"src",
"dist"
],
"funding": "https://github.com/sponsors/colinhacks",
"homepage": "https://zod.dev",
"keywords": ["typescript", "schema", "validation", "type", "inference"],
"keywords": [
"typescript",
"schema",
"validation",
"type",
"inference"
],
"license": "MIT",
"sideEffects": false,
"main": "./dist/commonjs/index.js",
Expand All @@ -17,7 +26,6 @@
"./package.json": "./package.json",
".": {
"import": {
"@zod/source": "./src/index.ts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
Expand All @@ -28,7 +36,6 @@
},
"./locales/*": {
"import": {
"@zod/source": "./src/locales/*",
"types": "./dist/esm/locales/*",
"default": "./dist/esm/locales/*"
},
Expand Down
9 changes: 7 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 46423ba

Please sign in to comment.