summaryrefslogtreecommitdiff
path: root/node_modules/zod/lib/benchmarks
diff options
context:
space:
mode:
authorakiyamn2023-09-24 23:22:21 +1000
committerakiyamn2023-09-24 23:22:21 +1000
commit4e87195739f2a5d9a05451b48773c8afdc680765 (patch)
tree9cba501844a4a11dcbdffc4050ed8189561c55ed /node_modules/zod/lib/benchmarks
downloadprice-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.tar.gz
price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.zip
Initial commit (by create-cloudflare CLI)
Diffstat (limited to 'node_modules/zod/lib/benchmarks')
-rw-r--r--node_modules/zod/lib/benchmarks/discriminatedUnion.d.ts5
-rw-r--r--node_modules/zod/lib/benchmarks/discriminatedUnion.js79
-rw-r--r--node_modules/zod/lib/benchmarks/index.d.ts1
-rw-r--r--node_modules/zod/lib/benchmarks/index.js46
-rw-r--r--node_modules/zod/lib/benchmarks/object.d.ts5
-rw-r--r--node_modules/zod/lib/benchmarks/object.js70
-rw-r--r--node_modules/zod/lib/benchmarks/primitives.d.ts5
-rw-r--r--node_modules/zod/lib/benchmarks/primitives.js136
-rw-r--r--node_modules/zod/lib/benchmarks/realworld.d.ts5
-rw-r--r--node_modules/zod/lib/benchmarks/realworld.js56
-rw-r--r--node_modules/zod/lib/benchmarks/string.d.ts5
-rw-r--r--node_modules/zod/lib/benchmarks/string.js55
-rw-r--r--node_modules/zod/lib/benchmarks/union.d.ts5
-rw-r--r--node_modules/zod/lib/benchmarks/union.js79
14 files changed, 552 insertions, 0 deletions
diff --git a/node_modules/zod/lib/benchmarks/discriminatedUnion.d.ts b/node_modules/zod/lib/benchmarks/discriminatedUnion.d.ts
new file mode 100644
index 0000000..9d2c302
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/discriminatedUnion.d.ts
@@ -0,0 +1,5 @@
+import Benchmark from "benchmark";
+declare const _default: {
+ suites: Benchmark.Suite[];
+};
+export default _default;
diff --git a/node_modules/zod/lib/benchmarks/discriminatedUnion.js b/node_modules/zod/lib/benchmarks/discriminatedUnion.js
new file mode 100644
index 0000000..ea148f6
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/discriminatedUnion.js
@@ -0,0 +1,79 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const benchmark_1 = __importDefault(require("benchmark"));
+const index_1 = require("../index");
+const doubleSuite = new benchmark_1.default.Suite("z.discriminatedUnion: double");
+const manySuite = new benchmark_1.default.Suite("z.discriminatedUnion: many");
+const aSchema = index_1.z.object({
+ type: index_1.z.literal("a"),
+});
+const objA = {
+ type: "a",
+};
+const bSchema = index_1.z.object({
+ type: index_1.z.literal("b"),
+});
+const objB = {
+ type: "b",
+};
+const cSchema = index_1.z.object({
+ type: index_1.z.literal("c"),
+});
+const objC = {
+ type: "c",
+};
+const dSchema = index_1.z.object({
+ type: index_1.z.literal("d"),
+});
+const double = index_1.z.discriminatedUnion("type", [aSchema, bSchema]);
+const many = index_1.z.discriminatedUnion("type", [aSchema, bSchema, cSchema, dSchema]);
+doubleSuite
+ .add("valid: a", () => {
+ double.parse(objA);
+})
+ .add("valid: b", () => {
+ double.parse(objB);
+})
+ .add("invalid: null", () => {
+ try {
+ double.parse(null);
+ }
+ catch (err) { }
+})
+ .add("invalid: wrong shape", () => {
+ try {
+ double.parse(objC);
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${doubleSuite.name}: ${e.target}`);
+});
+manySuite
+ .add("valid: a", () => {
+ many.parse(objA);
+})
+ .add("valid: c", () => {
+ many.parse(objC);
+})
+ .add("invalid: null", () => {
+ try {
+ many.parse(null);
+ }
+ catch (err) { }
+})
+ .add("invalid: wrong shape", () => {
+ try {
+ many.parse({ type: "unknown" });
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${manySuite.name}: ${e.target}`);
+});
+exports.default = {
+ suites: [doubleSuite, manySuite],
+};
diff --git a/node_modules/zod/lib/benchmarks/index.d.ts b/node_modules/zod/lib/benchmarks/index.d.ts
new file mode 100644
index 0000000..cb0ff5c
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/index.d.ts
@@ -0,0 +1 @@
+export {};
diff --git a/node_modules/zod/lib/benchmarks/index.js b/node_modules/zod/lib/benchmarks/index.js
new file mode 100644
index 0000000..71930b4
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/index.js
@@ -0,0 +1,46 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const discriminatedUnion_1 = __importDefault(require("./discriminatedUnion"));
+const object_1 = __importDefault(require("./object"));
+const primitives_1 = __importDefault(require("./primitives"));
+const realworld_1 = __importDefault(require("./realworld"));
+const string_1 = __importDefault(require("./string"));
+const union_1 = __importDefault(require("./union"));
+const argv = process.argv.slice(2);
+let suites = [];
+if (!argv.length) {
+ suites = [
+ ...realworld_1.default.suites,
+ ...primitives_1.default.suites,
+ ...string_1.default.suites,
+ ...object_1.default.suites,
+ ...union_1.default.suites,
+ ...discriminatedUnion_1.default.suites,
+ ];
+}
+else {
+ if (argv.includes("--realworld")) {
+ suites.push(...realworld_1.default.suites);
+ }
+ if (argv.includes("--primitives")) {
+ suites.push(...primitives_1.default.suites);
+ }
+ if (argv.includes("--string")) {
+ suites.push(...string_1.default.suites);
+ }
+ if (argv.includes("--object")) {
+ suites.push(...object_1.default.suites);
+ }
+ if (argv.includes("--union")) {
+ suites.push(...union_1.default.suites);
+ }
+ if (argv.includes("--discriminatedUnion")) {
+ suites.push(...discriminatedUnion_1.default.suites);
+ }
+}
+for (const suite of suites) {
+ suite.run();
+}
diff --git a/node_modules/zod/lib/benchmarks/object.d.ts b/node_modules/zod/lib/benchmarks/object.d.ts
new file mode 100644
index 0000000..9d2c302
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/object.d.ts
@@ -0,0 +1,5 @@
+import Benchmark from "benchmark";
+declare const _default: {
+ suites: Benchmark.Suite[];
+};
+export default _default;
diff --git a/node_modules/zod/lib/benchmarks/object.js b/node_modules/zod/lib/benchmarks/object.js
new file mode 100644
index 0000000..02f26c5
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/object.js
@@ -0,0 +1,70 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const benchmark_1 = __importDefault(require("benchmark"));
+const index_1 = require("../index");
+const emptySuite = new benchmark_1.default.Suite("z.object: empty");
+const shortSuite = new benchmark_1.default.Suite("z.object: short");
+const longSuite = new benchmark_1.default.Suite("z.object: long");
+const empty = index_1.z.object({});
+const short = index_1.z.object({
+ string: index_1.z.string(),
+});
+const long = index_1.z.object({
+ string: index_1.z.string(),
+ number: index_1.z.number(),
+ boolean: index_1.z.boolean(),
+});
+emptySuite
+ .add("valid", () => {
+ empty.parse({});
+})
+ .add("valid: extra keys", () => {
+ empty.parse({ string: "string" });
+})
+ .add("invalid: null", () => {
+ try {
+ empty.parse(null);
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${emptySuite.name}: ${e.target}`);
+});
+shortSuite
+ .add("valid", () => {
+ short.parse({ string: "string" });
+})
+ .add("valid: extra keys", () => {
+ short.parse({ string: "string", number: 42 });
+})
+ .add("invalid: null", () => {
+ try {
+ short.parse(null);
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${shortSuite.name}: ${e.target}`);
+});
+longSuite
+ .add("valid", () => {
+ long.parse({ string: "string", number: 42, boolean: true });
+})
+ .add("valid: extra keys", () => {
+ long.parse({ string: "string", number: 42, boolean: true, list: [] });
+})
+ .add("invalid: null", () => {
+ try {
+ long.parse(null);
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${longSuite.name}: ${e.target}`);
+});
+exports.default = {
+ suites: [emptySuite, shortSuite, longSuite],
+};
diff --git a/node_modules/zod/lib/benchmarks/primitives.d.ts b/node_modules/zod/lib/benchmarks/primitives.d.ts
new file mode 100644
index 0000000..9d2c302
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/primitives.d.ts
@@ -0,0 +1,5 @@
+import Benchmark from "benchmark";
+declare const _default: {
+ suites: Benchmark.Suite[];
+};
+export default _default;
diff --git a/node_modules/zod/lib/benchmarks/primitives.js b/node_modules/zod/lib/benchmarks/primitives.js
new file mode 100644
index 0000000..9ea5862
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/primitives.js
@@ -0,0 +1,136 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const benchmark_1 = __importDefault(require("benchmark"));
+const Mocker_1 = require("../__tests__/Mocker");
+const index_1 = require("../index");
+const val = new Mocker_1.Mocker();
+const enumSuite = new benchmark_1.default.Suite("z.enum");
+const enumSchema = index_1.z.enum(["a", "b", "c"]);
+enumSuite
+ .add("valid", () => {
+ enumSchema.parse("a");
+})
+ .add("invalid", () => {
+ try {
+ enumSchema.parse("x");
+ }
+ catch (e) { }
+})
+ .on("cycle", (e) => {
+ console.log(`z.enum: ${e.target}`);
+});
+const undefinedSuite = new benchmark_1.default.Suite("z.undefined");
+const undefinedSchema = index_1.z.undefined();
+undefinedSuite
+ .add("valid", () => {
+ undefinedSchema.parse(undefined);
+})
+ .add("invalid", () => {
+ try {
+ undefinedSchema.parse(1);
+ }
+ catch (e) { }
+})
+ .on("cycle", (e) => {
+ console.log(`z.undefined: ${e.target}`);
+});
+const literalSuite = new benchmark_1.default.Suite("z.literal");
+const short = "short";
+const bad = "bad";
+const literalSchema = index_1.z.literal("short");
+literalSuite
+ .add("valid", () => {
+ literalSchema.parse(short);
+})
+ .add("invalid", () => {
+ try {
+ literalSchema.parse(bad);
+ }
+ catch (e) { }
+})
+ .on("cycle", (e) => {
+ console.log(`z.literal: ${e.target}`);
+});
+const numberSuite = new benchmark_1.default.Suite("z.number");
+const numberSchema = index_1.z.number().int();
+numberSuite
+ .add("valid", () => {
+ numberSchema.parse(1);
+})
+ .add("invalid type", () => {
+ try {
+ numberSchema.parse("bad");
+ }
+ catch (e) { }
+})
+ .add("invalid number", () => {
+ try {
+ numberSchema.parse(0.5);
+ }
+ catch (e) { }
+})
+ .on("cycle", (e) => {
+ console.log(`z.number: ${e.target}`);
+});
+const dateSuite = new benchmark_1.default.Suite("z.date");
+const plainDate = index_1.z.date();
+const minMaxDate = index_1.z
+ .date()
+ .min(new Date("2021-01-01"))
+ .max(new Date("2030-01-01"));
+dateSuite
+ .add("valid", () => {
+ plainDate.parse(new Date());
+})
+ .add("invalid", () => {
+ try {
+ plainDate.parse(1);
+ }
+ catch (e) { }
+})
+ .add("valid min and max", () => {
+ minMaxDate.parse(new Date("2023-01-01"));
+})
+ .add("invalid min", () => {
+ try {
+ minMaxDate.parse(new Date("2019-01-01"));
+ }
+ catch (e) { }
+})
+ .add("invalid max", () => {
+ try {
+ minMaxDate.parse(new Date("2031-01-01"));
+ }
+ catch (e) { }
+})
+ .on("cycle", (e) => {
+ console.log(`z.date: ${e.target}`);
+});
+const symbolSuite = new benchmark_1.default.Suite("z.symbol");
+const symbolSchema = index_1.z.symbol();
+symbolSuite
+ .add("valid", () => {
+ symbolSchema.parse(val.symbol);
+})
+ .add("invalid", () => {
+ try {
+ symbolSchema.parse(1);
+ }
+ catch (e) { }
+})
+ .on("cycle", (e) => {
+ console.log(`z.symbol: ${e.target}`);
+});
+exports.default = {
+ suites: [
+ enumSuite,
+ undefinedSuite,
+ literalSuite,
+ numberSuite,
+ dateSuite,
+ symbolSuite,
+ ],
+};
diff --git a/node_modules/zod/lib/benchmarks/realworld.d.ts b/node_modules/zod/lib/benchmarks/realworld.d.ts
new file mode 100644
index 0000000..9d2c302
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/realworld.d.ts
@@ -0,0 +1,5 @@
+import Benchmark from "benchmark";
+declare const _default: {
+ suites: Benchmark.Suite[];
+};
+export default _default;
diff --git a/node_modules/zod/lib/benchmarks/realworld.js b/node_modules/zod/lib/benchmarks/realworld.js
new file mode 100644
index 0000000..06f67ab
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/realworld.js
@@ -0,0 +1,56 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const benchmark_1 = __importDefault(require("benchmark"));
+const index_1 = require("../index");
+const shortSuite = new benchmark_1.default.Suite("realworld");
+const People = index_1.z.array(index_1.z.object({
+ type: index_1.z.literal("person"),
+ hair: index_1.z.enum(["blue", "brown"]),
+ active: index_1.z.boolean(),
+ name: index_1.z.string(),
+ age: index_1.z.number().int(),
+ hobbies: index_1.z.array(index_1.z.string()),
+ address: index_1.z.object({
+ street: index_1.z.string(),
+ zip: index_1.z.string(),
+ country: index_1.z.string(),
+ }),
+}));
+let i = 0;
+function num() {
+ return ++i;
+}
+function str() {
+ return (++i % 100).toString(16);
+}
+function array(fn) {
+ return Array.from({ length: ++i % 10 }, () => fn());
+}
+const people = Array.from({ length: 100 }, () => {
+ return {
+ type: "person",
+ hair: i % 2 ? "blue" : "brown",
+ active: !!(i % 2),
+ name: str(),
+ age: num(),
+ hobbies: array(str),
+ address: {
+ street: str(),
+ zip: str(),
+ country: str(),
+ },
+ };
+});
+shortSuite
+ .add("valid", () => {
+ People.parse(people);
+})
+ .on("cycle", (e) => {
+ console.log(`${shortSuite.name}: ${e.target}`);
+});
+exports.default = {
+ suites: [shortSuite],
+};
diff --git a/node_modules/zod/lib/benchmarks/string.d.ts b/node_modules/zod/lib/benchmarks/string.d.ts
new file mode 100644
index 0000000..9d2c302
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/string.d.ts
@@ -0,0 +1,5 @@
+import Benchmark from "benchmark";
+declare const _default: {
+ suites: Benchmark.Suite[];
+};
+export default _default;
diff --git a/node_modules/zod/lib/benchmarks/string.js b/node_modules/zod/lib/benchmarks/string.js
new file mode 100644
index 0000000..14248d5
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/string.js
@@ -0,0 +1,55 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const benchmark_1 = __importDefault(require("benchmark"));
+const index_1 = require("../index");
+const SUITE_NAME = "z.string";
+const suite = new benchmark_1.default.Suite(SUITE_NAME);
+const empty = "";
+const short = "short";
+const long = "long".repeat(256);
+const manual = (str) => {
+ if (typeof str !== "string") {
+ throw new Error("Not a string");
+ }
+ return str;
+};
+const stringSchema = index_1.z.string();
+const optionalStringSchema = index_1.z.string().optional();
+const optionalNullableStringSchema = index_1.z.string().optional().nullable();
+suite
+ .add("empty string", () => {
+ stringSchema.parse(empty);
+})
+ .add("short string", () => {
+ stringSchema.parse(short);
+})
+ .add("long string", () => {
+ stringSchema.parse(long);
+})
+ .add("optional string", () => {
+ optionalStringSchema.parse(long);
+})
+ .add("nullable string", () => {
+ optionalNullableStringSchema.parse(long);
+})
+ .add("nullable (null) string", () => {
+ optionalNullableStringSchema.parse(null);
+})
+ .add("invalid: null", () => {
+ try {
+ stringSchema.parse(null);
+ }
+ catch (err) { }
+})
+ .add("manual parser: long", () => {
+ manual(long);
+})
+ .on("cycle", (e) => {
+ console.log(`${SUITE_NAME}: ${e.target}`);
+});
+exports.default = {
+ suites: [suite],
+};
diff --git a/node_modules/zod/lib/benchmarks/union.d.ts b/node_modules/zod/lib/benchmarks/union.d.ts
new file mode 100644
index 0000000..9d2c302
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/union.d.ts
@@ -0,0 +1,5 @@
+import Benchmark from "benchmark";
+declare const _default: {
+ suites: Benchmark.Suite[];
+};
+export default _default;
diff --git a/node_modules/zod/lib/benchmarks/union.js b/node_modules/zod/lib/benchmarks/union.js
new file mode 100644
index 0000000..0639e21
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/union.js
@@ -0,0 +1,79 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const benchmark_1 = __importDefault(require("benchmark"));
+const index_1 = require("../index");
+const doubleSuite = new benchmark_1.default.Suite("z.union: double");
+const manySuite = new benchmark_1.default.Suite("z.union: many");
+const aSchema = index_1.z.object({
+ type: index_1.z.literal("a"),
+});
+const objA = {
+ type: "a",
+};
+const bSchema = index_1.z.object({
+ type: index_1.z.literal("b"),
+});
+const objB = {
+ type: "b",
+};
+const cSchema = index_1.z.object({
+ type: index_1.z.literal("c"),
+});
+const objC = {
+ type: "c",
+};
+const dSchema = index_1.z.object({
+ type: index_1.z.literal("d"),
+});
+const double = index_1.z.union([aSchema, bSchema]);
+const many = index_1.z.union([aSchema, bSchema, cSchema, dSchema]);
+doubleSuite
+ .add("valid: a", () => {
+ double.parse(objA);
+})
+ .add("valid: b", () => {
+ double.parse(objB);
+})
+ .add("invalid: null", () => {
+ try {
+ double.parse(null);
+ }
+ catch (err) { }
+})
+ .add("invalid: wrong shape", () => {
+ try {
+ double.parse(objC);
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${doubleSuite.name}: ${e.target}`);
+});
+manySuite
+ .add("valid: a", () => {
+ many.parse(objA);
+})
+ .add("valid: c", () => {
+ many.parse(objC);
+})
+ .add("invalid: null", () => {
+ try {
+ many.parse(null);
+ }
+ catch (err) { }
+})
+ .add("invalid: wrong shape", () => {
+ try {
+ many.parse({ type: "unknown" });
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${manySuite.name}: ${e.target}`);
+});
+exports.default = {
+ suites: [doubleSuite, manySuite],
+};