Skip to content

Commit 3a963a3

Browse files
committed
migrate benchmarks to mitata
1 parent 57d21af commit 3a963a3

File tree

9 files changed

+771
-658
lines changed

9 files changed

+771
-658
lines changed

benchmarks/base58.js

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import _benchmark from 'benchmark';
2-
const { Benchmark } = _benchmark;
1+
import { group, bench, barplot, summary, run, do_not_optimize } from 'mitata';
32

43
import { makeBaseEncoder, makeBaseDecoder } from '@urlpack/base-codec';
54
import baseXCodec from 'base-x';
@@ -17,26 +16,52 @@ Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
1716
`);
1817
const text = urlpack.encode(buffer);
1918

20-
new Benchmark.Suite()
21-
.add('@urlpack/base-codec encode', () => {
22-
urlpack.encode(buffer);
23-
})
24-
.add('@urlpack/base-codec decode', () => {
25-
urlpack.decode(text);
26-
})
27-
.add('base-x encode', () => {
28-
baseX.encode(buffer);
29-
})
30-
.add('base-x decode', () => {
31-
baseX.decode(text);
32-
})
33-
.add('base58-js encode', () => {
34-
base58js.binary_to_base58(buffer);
35-
})
36-
.add('base58-js decode', () => {
37-
base58js.base58_to_binary(text);
38-
})
39-
.on('cycle', event => {
40-
console.log(event.target.toString());
41-
})
42-
.run();
19+
group('encode', () => {
20+
summary(() => {
21+
barplot(() => {
22+
bench('@urlpack/base-codec encode', () => {
23+
do_not_optimize(
24+
urlpack.encode(buffer),
25+
);
26+
}).baseline();
27+
28+
bench('base-x encode', () => {
29+
do_not_optimize(
30+
baseX.encode(buffer),
31+
);
32+
});
33+
34+
bench('base58-js encode', () => {
35+
do_not_optimize(
36+
base58js.binary_to_base58(buffer),
37+
);
38+
});
39+
});
40+
});
41+
});
42+
43+
group('decode', () => {
44+
summary(() => {
45+
barplot(() => {
46+
bench('@urlpack/base-codec decode', () => {
47+
do_not_optimize(
48+
urlpack.decode(text),
49+
);
50+
}).baseline();
51+
52+
bench('base-x decode', () => {
53+
do_not_optimize(
54+
baseX.decode(text),
55+
);
56+
});
57+
58+
bench('base58-js decode', () => {
59+
do_not_optimize(
60+
base58js.base58_to_binary(text),
61+
);
62+
});
63+
});
64+
});
65+
});
66+
67+
run();

benchmarks/dataview.js

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
1-
import _benchmark from 'benchmark';
2-
const { Benchmark } = _benchmark;
1+
import { bench, do_not_optimize, run } from 'mitata';
32

43
const bin = new Uint8Array(Array(10000).fill(0));
54
const staticView = new DataView(bin.buffer);
65
const staticViewOffset = new DataView(bin.buffer, 5000);
76

8-
new Benchmark.Suite()
9-
.add('direct access', () => {
10-
bin[5000]
11-
})
12-
.add('dataview from offset (static)', () => {
13-
staticViewOffset.getUint8(0)
14-
})
15-
.add('dataview from offset', () => {
7+
bench('direct access', () => {
8+
do_not_optimize(
9+
bin[5000],
10+
);
11+
});
12+
13+
bench('dataview from offset (static)', () => {
14+
do_not_optimize(
15+
staticViewOffset.getUint8(0),
16+
);
17+
});
18+
19+
bench('dataview from offset', () => {
1620
let view = new DataView(bin.buffer, 5000)
17-
view.getUint8(0)
18-
})
19-
.add('dataview get offset (static)', () => {
20-
staticView.getUint8(0, 5000)
21-
})
22-
.add('dataview get offset', () => {
21+
do_not_optimize(
22+
view.getUint8(0),
23+
);
24+
});
25+
26+
bench('dataview get offset (static)', () => {
27+
do_not_optimize(
28+
staticView.getUint8(0, 5000),
29+
);
30+
});
31+
32+
bench('dataview get offset', () => {
2333
let view = new DataView(bin.buffer)
24-
view.getUint8(0, 5000)
25-
})
26-
.on('cycle', event => {
27-
console.log(event.target.toString());
28-
})
29-
.run();
34+
do_not_optimize(
35+
view.getUint8(0, 5000),
36+
);
37+
});
38+
39+
run();
Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import _benchmark from 'benchmark';
2-
const { Benchmark } = _benchmark;
1+
import { group, summary, barplot, bench, run } from 'mitata';
32

43
import { makeMessagePackDecoder } from '@urlpack/msgpack';
54
const urlpack = makeMessagePackDecoder();
@@ -16,45 +15,48 @@ import * as msgpackr from 'msgpackr';
1615
const complex1 = new Uint8Array([0x82, 0xa1, 0x61, 0x81, 0xa1, 0x62, 0xa1, 0x63, 0xa1, 0x63, 0x94, 0xc0, 0xc0, 0xc0, 0x81, 0xa1, 0x64, 0xa1, 0x63]);
1716
const complex2 = new Uint8Array([0x88, 0xa3, 0x69, 0x6e, 0x74, 0x1, 0xa5, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0xcb, 0x3f, 0xe0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa7, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0xc3, 0xa4, 0x6e, 0x75, 0x6c, 0x6c, 0xc0, 0xa6, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0xa7, 0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72, 0xa5, 0x61, 0x72, 0x72, 0x61, 0x79, 0x92, 0xa3, 0x66, 0x6f, 0x6f, 0xa3, 0x62, 0x61, 0x72, 0xa6, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x82, 0xa3, 0x66, 0x6f, 0x6f, 0x1, 0xa3, 0x62, 0x61, 0x7a, 0xcb, 0x3f, 0xe0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa4, 0x64, 0x61, 0x74, 0x65, 0xd7, 0xff, 0xbe, 0x7f, 0x17, 0x0, 0x60, 0xf8, 0x3c, 0x5f]);
1817

19-
new Benchmark.Suite()
20-
.add('warmup', () => {
21-
urlpack.decode(complex1);
22-
msgpack.decode(complex1);
23-
msgpack5.decode(complex1);
24-
msgpackLite.decode(complex1);
25-
msgpackr.decode(complex1);
26-
})
27-
.add('decode complex 1 - @urlpack/msgpack', () => {
28-
urlpack.decode(complex1);
29-
})
30-
.add('decode complex 1 - @msgpack/msgpack', () => {
31-
msgpack.decode(complex1);
32-
})
33-
.add('decode complex 1 - msgpack5', () => {
34-
msgpack5.decode(complex1);
35-
})
36-
.add('decode complex 1 - msgpack-lite', () => {
37-
msgpackLite.decode(complex1);
38-
})
39-
.add('decode complex 1 - msgpackr', () => {
40-
msgpackr.decode(complex1);
41-
})
42-
.add('decode complex 2 - @urlpack/msgpack', () => {
43-
urlpack.decode(complex2);
44-
})
45-
.add('decode complex 2 - @msgpack/msgpack', () => {
46-
msgpack.decode(complex2);
47-
})
48-
.add('decode complex 2 - msgpack5', () => {
49-
msgpack5.decode(complex2);
50-
})
51-
.add('decode complex 2 - msgpack-lite', () => {
52-
msgpackLite.decode(complex2);
53-
})
54-
.add('decode complex 2 - msgpackr', () => {
55-
msgpackr.decode(complex2);
56-
})
57-
.on('cycle', event => {
58-
console.log(event.target.toString());
59-
})
60-
.run();
18+
group('decode complex 1', () => {
19+
summary(() => {
20+
barplot(() => {
21+
bench('@urlpack/msgpack', () => {
22+
urlpack.decode(complex1);
23+
}).gc('inner').baseline();
24+
bench('@msgpack/msgpack', () => {
25+
msgpack.decode(complex1);
26+
}).gc('inner');
27+
bench('msgpack5', () => {
28+
msgpack5.decode(complex1);
29+
}).gc('inner');
30+
bench('msgpack-lite', () => {
31+
msgpackLite.decode(complex1);
32+
}).gc('inner');
33+
bench('msgpackr', () => {
34+
msgpackr.decode(complex1);
35+
}).gc('inner');
36+
});
37+
});
38+
});
39+
40+
group('decode complex 2', () => {
41+
summary(() => {
42+
barplot(() => {
43+
bench('@urlpack/msgpack', () => {
44+
urlpack.decode(complex2);
45+
}).gc('inner').baseline();
46+
bench('@msgpack/msgpack', () => {
47+
msgpack.decode(complex2);
48+
}).gc('inner');
49+
bench('msgpack5', () => {
50+
msgpack5.decode(complex2);
51+
}).gc('inner');
52+
bench('msgpack-lite', () => {
53+
msgpackLite.decode(complex2);
54+
}).gc('inner');
55+
bench('msgpackr', () => {
56+
msgpackr.decode(complex2);
57+
}).gc('inner');
58+
});
59+
});
60+
});
61+
62+
run();

0 commit comments

Comments
 (0)