-
Notifications
You must be signed in to change notification settings - Fork 4
/
benchmark.ts
36 lines (30 loc) · 979 Bytes
/
benchmark.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
/* eslint-disable no-console */
import { randomBytes } from 'crypto';
import { Suite, Event } from 'benchmark';
import { compress as compressNative } from 'iltorb';
import { compress as compressWasm } from './pkg';
// warmup
compressNative(randomBytes(1024 * 1024));
compressWasm(randomBytes(1024 * 1024));
[1, 1024, 1024 * 1014]
.reduce((acc, size): Suite => {
acc.add(`iltorb (native compress)\t${size} byte(s)\t`, {
defer: true,
fn: async (deffered: { resolve: Function }): Promise<void> => {
await compressNative(randomBytes(size));
deffered.resolve();
},
});
acc.add(`wasm-brotli (wasm compress)\t${size} byte(s)\t`, {
defer: true,
fn: async (deffered: { resolve: Function }): Promise<void> => {
compressWasm(randomBytes(size));
deffered.resolve();
},
});
return acc;
}, new Suite())
.on('cycle', (event: Event): void => {
console.log(`${event.target}`);
})
.run();