-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
69 lines (61 loc) · 2.05 KB
/
test.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
60
61
62
63
64
65
66
67
68
69
import { baseline, bench, group, run } from '../src/index.js'
bench('noop', () => {}, {
samples: 64,
time: 1000,
now: () => 1e6 * performance.now(),
before: () => {},
after: () => {},
})
bench('async noop', async () => {})
baseline('baseline noop', () => {})
bench('async promise noop', () => Promise.resolve())
bench('error', () => {
throw new Error('error')
})
bench('async promise reject', () => Promise.reject(new Error('reject')))
group(() => {
bench('a', () => {})
bench('b', () => {})
bench('e', () => {
throw new Error("error 'e'")
})
bench('r', () => Promise.reject(new Error("reject 'r'")))
})
group('group', () => {
baseline('baseline noop', () => {})
bench('Date.now()', () => {
Date.now()
})
bench('performance.now()', () => {
performance.now()
})
})
group({ summary: false, samples: 64, time: 10000, after: () => {} }, () => {
bench('aa', () => {})
bench('bb', () => {})
})
group({ name: 'group2', summary: false }, () => {
bench('new Array(0)', () => {
new Array(0)
})
bench('new Array(1024)', () => {
new Array(1024)
})
})
const report = await run({
latency: true, // enable/disable time/iter column (default: true)
throughput: true, // enable/disable iters/s column (default: true)
json: false, // enable/disable json output or set json output indentation (default: false)
colors: true, // enable/disable colors (default: true)
latencyMinMax: true, // enable/disable latency (min...max) column (default: true)
latencyPercentiles: true, // enable/disable latency percentile columns (default: true)
})
console.log(report)
await run({
latency: true, // enable/disable time/iter column (default: true)
throughput: true, // enable/disable iters/s column (default: true)
json: false, // enable/disable json output or set json output indentation (default: false)
colors: true, // enable/disable colors (default: true)
latencyMinMax: true, // enable/disable latency (min...max) column (default: true)
latencyPercentiles: true, // enable/disable latency percentile columns (default: true)
})