/
base.bench.ts
59 lines (48 loc) · 1 KB
/
base.bench.ts
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { bench, describe } from 'vitest'
describe('sort', () => {
bench('normal', () => {
const x = [1, 5, 4, 2, 3]
x.sort((a, b) => {
return a - b
})
}, { iterations: 5, time: 0 })
bench('reverse', () => {
const x = [1, 5, 4, 2, 3]
x.reverse().sort((a, b) => {
return a - b
})
}, { iterations: 5, time: 0 })
// TODO: move to failed tests
// should not be collected
// it('test', () => {
// expect(1 + 1).toBe(3)
// })
})
function timeout(time: number) {
return new Promise((resolve) => {
setTimeout(resolve, time)
})
}
describe('timeout', () => {
bench('timeout100', async () => {
await timeout(100)
}, {
setup() {
},
teardown() {
},
})
bench('timeout75', async () => {
await timeout(75)
})
bench('timeout50', async () => {
await timeout(50)
})
bench('timeout25', async () => {
await timeout(25)
})
// TODO: move to failed tests
// test('reduce', () => {
// expect(1 - 1).toBe(2)
// })
})