Skip to content

Commit 1c1f780

Browse files
committed
☕ Add benchmark tests
1 parent f8ae35d commit 1c1f780

File tree

2 files changed

+210
-0
lines changed

2 files changed

+210
-0
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,15 @@ jobs:
3838
run: |
3939
deno task test
4040
timeout-minutes: 5
41+
42+
bench:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v3
46+
- uses: denoland/setup-deno@v1
47+
with:
48+
deno-version: ${{ env.DENO_VERSION }}
49+
- name: Test
50+
run: |
51+
deno bench
52+
timeout-minutes: 5

is_bench.ts

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
import is from "./is.ts";
2+
3+
const cs: unknown[] = [
4+
"Hello world",
5+
12345,
6+
67890n,
7+
true,
8+
["a", 1, true],
9+
["a", "b", "c"],
10+
{ a: "a", b: "b", c: "c" },
11+
{ a: "a", b: 1, c: true },
12+
() => {},
13+
new Date(),
14+
null,
15+
undefined,
16+
Symbol("a"),
17+
];
18+
19+
Deno.bench({
20+
name: "Warm-up",
21+
fn: () => {},
22+
});
23+
24+
Deno.bench({
25+
name: "is.String",
26+
fn: () => {
27+
for (const c of cs) {
28+
is.String(c);
29+
}
30+
},
31+
});
32+
33+
Deno.bench({
34+
name: "is.Number",
35+
fn: () => {
36+
for (const c of cs) {
37+
is.Number(c);
38+
}
39+
},
40+
});
41+
42+
Deno.bench({
43+
name: "is.BigInt",
44+
fn: () => {
45+
for (const c of cs) {
46+
is.BigInt(c);
47+
}
48+
},
49+
});
50+
51+
Deno.bench({
52+
name: "is.Boolean",
53+
fn: () => {
54+
for (const c of cs) {
55+
is.Boolean(c);
56+
}
57+
},
58+
});
59+
60+
Deno.bench({
61+
name: "is.Array",
62+
fn: () => {
63+
for (const c of cs) {
64+
is.Array(c);
65+
}
66+
},
67+
});
68+
69+
Deno.bench({
70+
name: "is.ArrayOf",
71+
fn: () => {
72+
const pred = is.ArrayOf(is.String);
73+
for (const c of cs) {
74+
pred(c);
75+
}
76+
},
77+
});
78+
79+
const predTup = [is.String, is.Number, is.Boolean] as const;
80+
Deno.bench({
81+
name: "is.TupleOf",
82+
fn: () => {
83+
const pred = is.TupleOf(predTup);
84+
for (const c of cs) {
85+
pred(c);
86+
}
87+
},
88+
});
89+
90+
Deno.bench({
91+
name: "is.UniformTupleOf",
92+
fn: () => {
93+
const pred = is.UniformTupleOf(3, is.String);
94+
for (const c of cs) {
95+
pred(c);
96+
}
97+
},
98+
});
99+
100+
Deno.bench({
101+
name: "is.Record",
102+
fn: () => {
103+
for (const c of cs) {
104+
is.Record(c);
105+
}
106+
},
107+
});
108+
109+
Deno.bench({
110+
name: "is.RecordOf",
111+
fn: () => {
112+
const pred = is.RecordOf(is.String);
113+
for (const c of cs) {
114+
pred(c);
115+
}
116+
},
117+
});
118+
119+
const predObj = {
120+
a: is.String,
121+
b: is.Number,
122+
c: is.Boolean,
123+
};
124+
Deno.bench({
125+
name: "is.ObjectOf",
126+
fn: () => {
127+
const pred = is.ObjectOf(predObj);
128+
for (const c of cs) {
129+
pred(c);
130+
}
131+
},
132+
});
133+
134+
Deno.bench({
135+
name: "is.Function",
136+
fn: () => {
137+
for (const c of cs) {
138+
is.Function(c);
139+
}
140+
},
141+
});
142+
143+
Deno.bench({
144+
name: "is.InstanceOf",
145+
fn: () => {
146+
const pred = is.InstanceOf(Date);
147+
for (const c of cs) {
148+
pred(c);
149+
}
150+
},
151+
});
152+
153+
Deno.bench({
154+
name: "is.Null",
155+
fn: () => {
156+
for (const c of cs) {
157+
is.Null(c);
158+
}
159+
},
160+
});
161+
162+
Deno.bench({
163+
name: "is.Undefined",
164+
fn: () => {
165+
for (const c of cs) {
166+
is.Undefined(c);
167+
}
168+
},
169+
});
170+
171+
Deno.bench({
172+
name: "is.Nullish",
173+
fn: () => {
174+
for (const c of cs) {
175+
is.Nullish(c);
176+
}
177+
},
178+
});
179+
180+
Deno.bench({
181+
name: "is.Symbol",
182+
fn: () => {
183+
for (const c of cs) {
184+
is.Symbol(c);
185+
}
186+
},
187+
});
188+
189+
const preds = [is.String, is.Number, is.Boolean];
190+
Deno.bench({
191+
name: "is.OneOf",
192+
fn: () => {
193+
const pred = is.OneOf(preds);
194+
for (const c of cs) {
195+
pred(c);
196+
}
197+
},
198+
});

0 commit comments

Comments
 (0)