summaryrefslogtreecommitdiff
path: root/node_modules/zod/lib/benchmarks/object.js
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/object.js
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/object.js')
-rw-r--r--node_modules/zod/lib/benchmarks/object.js70
1 files changed, 70 insertions, 0 deletions
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],
+};