Skip to content

Commit b14912b

Browse files
committed
👍 Add missing benchmark tests
1 parent 8021487 commit b14912b

File tree

1 file changed

+140
-24
lines changed

1 file changed

+140
-24
lines changed

is_bench.ts

Lines changed: 140 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ Deno.bench({
2121
fn: () => {},
2222
});
2323

24+
Deno.bench({
25+
name: "is.Any",
26+
fn: () => {
27+
for (const c of cs) {
28+
is.Any(c);
29+
}
30+
},
31+
});
32+
33+
Deno.bench({
34+
name: "is.Unknown",
35+
fn: () => {
36+
for (const c of cs) {
37+
is.Unknown(c);
38+
}
39+
},
40+
});
41+
2442
Deno.bench({
2543
name: "is.String",
2644
fn: () => {
@@ -67,7 +85,7 @@ Deno.bench({
6785
});
6886

6987
Deno.bench({
70-
name: "is.ArrayOf",
88+
name: "is.ArrayOf<T>",
7189
fn: () => {
7290
const pred = is.ArrayOf(is.String);
7391
for (const c of cs) {
@@ -78,7 +96,7 @@ Deno.bench({
7896

7997
const isArrayOfPred = is.ArrayOf(is.String);
8098
Deno.bench({
81-
name: "is.ArrayOf (pre)",
99+
name: "is.ArrayOf<T> (pre)",
82100
fn: () => {
83101
for (const c of cs) {
84102
isArrayOfPred(c);
@@ -88,7 +106,7 @@ Deno.bench({
88106

89107
const predTup = [is.String, is.Number, is.Boolean] as const;
90108
Deno.bench({
91-
name: "is.TupleOf",
109+
name: "is.TupleOf<T>",
92110
fn: () => {
93111
const pred = is.TupleOf(predTup);
94112
for (const c of cs) {
@@ -99,7 +117,7 @@ Deno.bench({
99117

100118
const isTupleOfPred = is.TupleOf(predTup);
101119
Deno.bench({
102-
name: "is.TupleOf (pre)",
120+
name: "is.TupleOf<T> (pre)",
103121
fn: () => {
104122
for (const c of cs) {
105123
isTupleOfPred(c);
@@ -108,7 +126,67 @@ Deno.bench({
108126
});
109127

110128
Deno.bench({
111-
name: "is.UniformTupleOf",
129+
name: "is.TupleOf<T, E>",
130+
fn: () => {
131+
const pred = is.TupleOf(predTup, is.Array);
132+
for (const c of cs) {
133+
pred(c);
134+
}
135+
},
136+
});
137+
138+
const isTupleOfElsePred = is.TupleOf(predTup, is.Array);
139+
Deno.bench({
140+
name: "is.TupleOf<T, E> (pre)",
141+
fn: () => {
142+
for (const c of cs) {
143+
isTupleOfElsePred(c);
144+
}
145+
},
146+
});
147+
148+
Deno.bench({
149+
name: "is.ReadonlyTupleOf<T>",
150+
fn: () => {
151+
const pred = is.ReadonlyTupleOf(predTup);
152+
for (const c of cs) {
153+
pred(c);
154+
}
155+
},
156+
});
157+
158+
const isReadonlyTupleOfPred = is.ReadonlyTupleOf(predTup);
159+
Deno.bench({
160+
name: "is.ReadonlyTupleOf<T> (pre)",
161+
fn: () => {
162+
for (const c of cs) {
163+
isReadonlyTupleOfPred(c);
164+
}
165+
},
166+
});
167+
168+
Deno.bench({
169+
name: "is.ReadonlyTupleOf<T, E>",
170+
fn: () => {
171+
const pred = is.ReadonlyTupleOf(predTup, is.Array);
172+
for (const c of cs) {
173+
pred(c);
174+
}
175+
},
176+
});
177+
178+
const isReadonlyTupleOfElsePred = is.ReadonlyTupleOf(predTup, is.Array);
179+
Deno.bench({
180+
name: "is.ReadonlyTupleOf<T, E> (pre)",
181+
fn: () => {
182+
for (const c of cs) {
183+
isReadonlyTupleOfElsePred(c);
184+
}
185+
},
186+
});
187+
188+
Deno.bench({
189+
name: "is.UniformTupleOf<N, T>",
112190
fn: () => {
113191
const pred = is.UniformTupleOf(3, is.String);
114192
for (const c of cs) {
@@ -119,14 +197,34 @@ Deno.bench({
119197

120198
const isUniformTupleOfPred = is.UniformTupleOf(3, is.String);
121199
Deno.bench({
122-
name: "is.UniformTupleOf (pre)",
200+
name: "is.UniformTupleOf<N, T> (pre)",
123201
fn: () => {
124202
for (const c of cs) {
125203
isUniformTupleOfPred(c);
126204
}
127205
},
128206
});
129207

208+
Deno.bench({
209+
name: "is.ReadonlyUniformTupleOf<N, T>",
210+
fn: () => {
211+
const pred = is.ReadonlyUniformTupleOf(3, is.String);
212+
for (const c of cs) {
213+
pred(c);
214+
}
215+
},
216+
});
217+
218+
const isReadonlyUniformTupleOfPred = is.ReadonlyUniformTupleOf(3, is.String);
219+
Deno.bench({
220+
name: "is.ReadonlyUniformTupleOf<N, T> (pre)",
221+
fn: () => {
222+
for (const c of cs) {
223+
isReadonlyUniformTupleOfPred(c);
224+
}
225+
},
226+
});
227+
130228
Deno.bench({
131229
name: "is.Record",
132230
fn: () => {
@@ -137,7 +235,7 @@ Deno.bench({
137235
});
138236

139237
Deno.bench({
140-
name: "is.RecordOf",
238+
name: "is.RecordOf<T>",
141239
fn: () => {
142240
const pred = is.RecordOf(is.String);
143241
for (const c of cs) {
@@ -148,7 +246,7 @@ Deno.bench({
148246

149247
const isRecordOfPred = is.RecordOf(is.String);
150248
Deno.bench({
151-
name: "is.RecordOf (pre)",
249+
name: "is.RecordOf<T> (pre)",
152250
fn: () => {
153251
for (const c of cs) {
154252
isRecordOfPred(c);
@@ -162,7 +260,7 @@ const predObj = {
162260
c: is.Boolean,
163261
} as const;
164262
Deno.bench({
165-
name: "is.ObjectOf",
263+
name: "is.ObjectOf<T>",
166264
fn: () => {
167265
const pred = is.ObjectOf(predObj);
168266
for (const c of cs) {
@@ -171,7 +269,7 @@ Deno.bench({
171269
},
172270
});
173271
Deno.bench({
174-
name: "is.ObjectOf (strict)",
272+
name: "is.ObjectOf<T> (strict)",
175273
fn: () => {
176274
const pred = is.ObjectOf(predObj, { strict: true });
177275
for (const c of cs) {
@@ -182,7 +280,7 @@ Deno.bench({
182280

183281
const isObjectOfPred = is.ObjectOf(predObj);
184282
Deno.bench({
185-
name: "is.ObjectOf (pre)",
283+
name: "is.ObjectOf<T> (pre)",
186284
fn: () => {
187285
for (const c of cs) {
188286
isObjectOfPred(c);
@@ -192,7 +290,7 @@ Deno.bench({
192290

193291
const isObjectOfStrictPred = is.ObjectOf(predObj, { strict: true });
194292
Deno.bench({
195-
name: "is.ObjectOf (pre, strict)",
293+
name: "is.ObjectOf<T> (pre, strict)",
196294
fn: () => {
197295
for (const c of cs) {
198296
isObjectOfStrictPred(c);
@@ -210,7 +308,25 @@ Deno.bench({
210308
});
211309

212310
Deno.bench({
213-
name: "is.InstanceOf",
311+
name: "is.SyncFunction",
312+
fn: () => {
313+
for (const c of cs) {
314+
is.SyncFunction(c);
315+
}
316+
},
317+
});
318+
319+
Deno.bench({
320+
name: "is.AsyncFunction",
321+
fn: () => {
322+
for (const c of cs) {
323+
is.AsyncFunction(c);
324+
}
325+
},
326+
});
327+
328+
Deno.bench({
329+
name: "is.InstanceOf<T>",
214330
fn: () => {
215331
const pred = is.InstanceOf(Date);
216332
for (const c of cs) {
@@ -221,7 +337,7 @@ Deno.bench({
221337

222338
const isInstanceOfPred = is.InstanceOf(Date);
223339
Deno.bench({
224-
name: "is.InstanceOf (pre)",
340+
name: "is.InstanceOf<T> (pre)",
225341
fn: () => {
226342
for (const c of cs) {
227343
isInstanceOfPred(c);
@@ -276,7 +392,7 @@ Deno.bench({
276392

277393
const predLiteral = "hello";
278394
Deno.bench({
279-
name: "is.LiteralOf",
395+
name: "is.LiteralOf<T>",
280396
fn: () => {
281397
const pred = is.LiteralOf(predLiteral);
282398
for (const c of cs) {
@@ -287,7 +403,7 @@ Deno.bench({
287403

288404
const isLiteralOfPred = is.LiteralOf(predLiteral);
289405
Deno.bench({
290-
name: "is.LiteralOf (pre)",
406+
name: "is.LiteralOf<T> (pre)",
291407
fn: () => {
292408
for (const c of cs) {
293409
isLiteralOfPred(c);
@@ -297,7 +413,7 @@ Deno.bench({
297413

298414
const predLiteralOne = ["hello", "world"] as const;
299415
Deno.bench({
300-
name: "is.LiteralOneOf",
416+
name: "is.LiteralOneOf<T>",
301417
fn: () => {
302418
const pred = is.LiteralOneOf(predLiteralOne);
303419
for (const c of cs) {
@@ -308,7 +424,7 @@ Deno.bench({
308424

309425
const isLiteralOneOfPred = is.LiteralOneOf(predLiteralOne);
310426
Deno.bench({
311-
name: "is.LiteralOneOf (pre)",
427+
name: "is.LiteralOneOf<T> (pre)",
312428
fn: () => {
313429
for (const c of cs) {
314430
isLiteralOneOfPred(c);
@@ -318,7 +434,7 @@ Deno.bench({
318434

319435
const predsOne = [is.String, is.Number, is.Boolean] as const;
320436
Deno.bench({
321-
name: "is.OneOf",
437+
name: "is.OneOf<T>",
322438
fn: () => {
323439
const pred = is.OneOf(predsOne);
324440
for (const c of cs) {
@@ -329,7 +445,7 @@ Deno.bench({
329445

330446
const isOneOfPred = is.OneOf(predsOne);
331447
Deno.bench({
332-
name: "is.OneOf (pre)",
448+
name: "is.OneOf<T> (pre)",
333449
fn: () => {
334450
for (const c of cs) {
335451
isOneOfPred(c);
@@ -339,7 +455,7 @@ Deno.bench({
339455

340456
const predsAll = [is.String, is.Number, is.Boolean] as const;
341457
Deno.bench({
342-
name: "is.AllOf",
458+
name: "is.AllOf<T>",
343459
fn: () => {
344460
const pred = is.AllOf(predsAll);
345461
for (const c of cs) {
@@ -350,7 +466,7 @@ Deno.bench({
350466

351467
const isAllOfPred = is.AllOf(predsAll);
352468
Deno.bench({
353-
name: "is.AllOf (pre)",
469+
name: "is.AllOf<T> (pre)",
354470
fn: () => {
355471
for (const c of cs) {
356472
isAllOfPred(c);
@@ -359,7 +475,7 @@ Deno.bench({
359475
});
360476

361477
Deno.bench({
362-
name: "is.OptionalOf",
478+
name: "is.OptionalOf<T>",
363479
fn: () => {
364480
const pred = is.OptionalOf(is.String);
365481
for (const c of cs) {
@@ -370,7 +486,7 @@ Deno.bench({
370486

371487
const isOptionalOfPred = is.OptionalOf(is.String);
372488
Deno.bench({
373-
name: "is.OptionalOf (pre)",
489+
name: "is.OptionalOf<T> (pre)",
374490
fn: () => {
375491
for (const c of cs) {
376492
isOptionalOfPred(c);

0 commit comments

Comments
 (0)