From 4e87195739f2a5d9a05451b48773c8afdc680765 Mon Sep 17 00:00:00 2001 From: akiyamn Date: Sun, 24 Sep 2023 23:22:21 +1000 Subject: Initial commit (by create-cloudflare CLI) --- node_modules/zod/lib/benchmarks/realworld.js | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 node_modules/zod/lib/benchmarks/realworld.js (limited to 'node_modules/zod/lib/benchmarks/realworld.js') 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], +}; -- cgit v1.2.3