Skip to content

Commit 0a7dfc5

Browse files
committed
📝 Add benchamrk for pre-defined predicates
1 parent 9cdb140 commit 0a7dfc5

File tree

1 file changed

+83
-3
lines changed

1 file changed

+83
-3
lines changed

is_bench.ts

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ Deno.bench({
7676
},
7777
});
7878

79+
const isArrayOfPred = is.ArrayOf(is.String);
80+
Deno.bench({
81+
name: "is.ArrayOf (pre)",
82+
fn: () => {
83+
for (const c of cs) {
84+
isArrayOfPred(c);
85+
}
86+
},
87+
});
88+
7989
const predTup = [is.String, is.Number, is.Boolean] as const;
8090
Deno.bench({
8191
name: "is.TupleOf",
@@ -87,6 +97,16 @@ Deno.bench({
8797
},
8898
});
8999

100+
const isTupleOfPred = is.TupleOf(predTup);
101+
Deno.bench({
102+
name: "is.TupleOf (pre)",
103+
fn: () => {
104+
for (const c of cs) {
105+
isTupleOfPred(c);
106+
}
107+
},
108+
});
109+
90110
Deno.bench({
91111
name: "is.UniformTupleOf",
92112
fn: () => {
@@ -97,6 +117,16 @@ Deno.bench({
97117
},
98118
});
99119

120+
const isUniformTupleOfPred = is.UniformTupleOf(3, is.String);
121+
Deno.bench({
122+
name: "is.UniformTupleOf (pre)",
123+
fn: () => {
124+
for (const c of cs) {
125+
isUniformTupleOfPred(c);
126+
}
127+
},
128+
});
129+
100130
Deno.bench({
101131
name: "is.Record",
102132
fn: () => {
@@ -116,11 +146,21 @@ Deno.bench({
116146
},
117147
});
118148

149+
const isRecordOfPred = is.RecordOf(is.String);
150+
Deno.bench({
151+
name: "is.RecordOf (pre)",
152+
fn: () => {
153+
for (const c of cs) {
154+
isRecordOfPred(c);
155+
}
156+
},
157+
});
158+
119159
const predObj = {
120160
a: is.String,
121161
b: is.Number,
122162
c: is.Boolean,
123-
};
163+
} as const;
124164
Deno.bench({
125165
name: "is.ObjectOf",
126166
fn: () => {
@@ -131,6 +171,16 @@ Deno.bench({
131171
},
132172
});
133173

174+
const isObjectOfPred = is.ObjectOf(predObj);
175+
Deno.bench({
176+
name: "is.ObjectOf (pre)",
177+
fn: () => {
178+
for (const c of cs) {
179+
isObjectOfPred(c);
180+
}
181+
},
182+
});
183+
134184
Deno.bench({
135185
name: "is.Function",
136186
fn: () => {
@@ -150,6 +200,16 @@ Deno.bench({
150200
},
151201
});
152202

203+
const isInstanceOfPred = is.InstanceOf(Date);
204+
Deno.bench({
205+
name: "is.InstanceOf (pre)",
206+
fn: () => {
207+
for (const c of cs) {
208+
isInstanceOfPred(c);
209+
}
210+
},
211+
});
212+
153213
Deno.bench({
154214
name: "is.Null",
155215
fn: () => {
@@ -186,17 +246,27 @@ Deno.bench({
186246
},
187247
});
188248

189-
const preds = [is.String, is.Number, is.Boolean];
249+
const predsOne = [is.String, is.Number, is.Boolean] as const;
190250
Deno.bench({
191251
name: "is.OneOf",
192252
fn: () => {
193-
const pred = is.OneOf(preds);
253+
const pred = is.OneOf(predsOne);
194254
for (const c of cs) {
195255
pred(c);
196256
}
197257
},
198258
});
199259

260+
const isOneOfPred = is.OneOf(predsOne);
261+
Deno.bench({
262+
name: "is.OneOf (pre)",
263+
fn: () => {
264+
for (const c of cs) {
265+
isOneOfPred(c);
266+
}
267+
},
268+
});
269+
200270
Deno.bench({
201271
name: "is.OptionalOf",
202272
fn: () => {
@@ -206,3 +276,13 @@ Deno.bench({
206276
}
207277
},
208278
});
279+
280+
const isOptionalOfPred = is.OptionalOf(is.String);
281+
Deno.bench({
282+
name: "is.OptionalOf (pre)",
283+
fn: () => {
284+
for (const c of cs) {
285+
isOptionalOfPred(c);
286+
}
287+
},
288+
});

0 commit comments

Comments
 (0)