diff options
| author | akiyamn | 2023-09-24 23:22:21 +1000 |
|---|---|---|
| committer | akiyamn | 2023-09-24 23:22:21 +1000 |
| commit | 4e87195739f2a5d9a05451b48773c8afdc680765 (patch) | |
| tree | 9cba501844a4a11dcbdffc4050ed8189561c55ed /node_modules/zod/lib/benchmarks/string.js | |
| download | price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.tar.gz price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.zip | |
Initial commit (by create-cloudflare CLI)
Diffstat (limited to 'node_modules/zod/lib/benchmarks/string.js')
| -rw-r--r-- | node_modules/zod/lib/benchmarks/string.js | 55 |
1 files changed, 55 insertions, 0 deletions
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], +}; |
