string.js
1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var benchmark_1 = __importDefault(require("benchmark"));
var index_1 = require("../index");
var SUITE_NAME = "z.string";
var suite = new benchmark_1.default.Suite(SUITE_NAME);
var empty = "";
var short = "short";
var long = "long".repeat(256);
var manual = function (str) {
if (typeof str !== "string") {
throw new Error("Not a string");
}
return str;
};
var stringSchema = index_1.z.string();
suite
.add("empty string", function () {
stringSchema.parse(empty);
})
.add("short string", function () {
stringSchema.parse(short);
})
.add("long string", function () {
stringSchema.parse(long);
})
.add("invalid: null", function () {
try {
stringSchema.parse(null);
}
catch (err) { }
})
.add("manual parser: long", function () {
manual(long);
})
.on("cycle", function (e) {
console.log("".concat(SUITE_NAME, ": ").concat(e.target));
});
exports.default = {
suites: [suite],
};