Skip to content

Commit 559191d

Browse files
authored
chore: add protobuf-ts to benchmarks (#68)
1 parent b1316fa commit 559191d

File tree

8 files changed

+634
-227
lines changed

8 files changed

+634
-227
lines changed

packages/protons-benchmark/README.md

+30-11
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,40 @@ Run the benchmark suite:
3535
```console
3636
$ npm start
3737

38-
Running "Encode/Decode" suite...
39-
Progress: 100%
38+
> protons-benchmark@0.0.0 prestart
39+
> npm run build
4040

41-
pbjs:
42-
12 166 ops/s, ±3.92% | 5.12% slower
4341

44-
protons:
45-
9 755 ops/s, ±2.19% | slowest, 23.93% slower
42+
> protons-benchmark@0.0.0 build
43+
> aegir build --no-bundle && cp -R src/protobufjs dist/src/protobufjs
4644

47-
protobufjs:
48-
12 823 ops/s, ±2.02% | fastest
45+
[15:02:28] tsc [started]
46+
[15:02:32] tsc [completed]
4947

50-
Finished 3 cases!
51-
Fastest: protobufjs
52-
Slowest: protons
48+
> protons-benchmark@0.0.0 start
49+
> node dist/src/index.js
50+
51+
pbjs x 11,798 ops/sec ±4.58% (88 runs sampled)
52+
protons x 11,693 ops/sec ±2.69% (85 runs sampled)
53+
protobuf.js x 12,419 ops/sec ±1.66% (88 runs sampled)
54+
@protobuf-ts x 10,536 ops/sec ±3.14% (85 runs sampled)
55+
Fastest is protobuf.js
56+
```
57+
58+
Or in a browser:
59+
60+
```console
61+
$ npm run start:browser
62+
63+
> protons-benchmark@0.0.0 start:browser
64+
> npx playwright-test dist/src/index.js --runner benchmark
65+
66+
✔ chromium set up
67+
pbjs x 19,027 ops/sec ±0.86% (67 runs sampled)
68+
protons x 18,901 ops/sec ±0.65% (67 runs sampled)
69+
protobuf.js x 18,937 ops/sec ±0.55% (65 runs sampled)
70+
@protobuf-ts x 16,669 ops/sec ±0.49% (68 runs sampled)
71+
Fastest is pbjs,protobuf.js
5372
```
5473

5574
## License

packages/protons-benchmark/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
},
5757
"ignorePatterns": [
5858
"src/pbjs/*",
59+
"src/protobuf-ts/*",
5960
"src/protobufjs/*"
6061
]
6162
},
@@ -65,9 +66,12 @@
6566
"dep-check": "aegir dep-check",
6667
"build": "aegir build --no-bundle && cp -R src/protobufjs dist/src/protobufjs",
6768
"prestart": "npm run build",
68-
"start": "node dist/src/index.js"
69+
"start": "node dist/src/index.js",
70+
"start:browser": "npx playwright-test dist/src/index.js --runner benchmark"
6971
},
7072
"dependencies": {
73+
"@protobuf-ts/plugin": "^2.8.1",
74+
"@protobuf-ts/runtime": "^2.8.1",
7175
"@types/benchmark": "^2.1.1",
7276
"aegir": "^37.0.5",
7377
"benchmark": "^2.1.4",

packages/protons-benchmark/src/bench.proto

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ message Bar {
99
}
1010

1111
enum FOO {
12+
NONE=0;
1213
LOL=1;
1314
ABE=3;
1415
}
@@ -19,7 +20,7 @@ message Yo {
1920

2021
message Lol {
2122
optional string lol = 1;
22-
required Bar b = 2;
23+
Bar b = 2;
2324
}
2425

2526
message Test {

packages/protons-benchmark/src/index.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { expect } from 'aegir/chai'
1010
import { Test as ProtonsTest } from './protons/bench.js'
1111
import { encodeTest as pbjsEncodeTest, decodeTest as pbjsDecodeTest } from './pbjs/bench.js'
1212
import { Test as ProtobufjsTest } from './protobufjs/bench.js'
13+
import { Test as ProtobufTsTest } from './protobuf-ts/bench.js'
1314

1415
const message = {
1516
meh: {
@@ -46,12 +47,18 @@ new Benchmark.Suite()
4647

4748
expectDecodedCorrectly(result)
4849
})
49-
.add('protobufjs', () => {
50+
.add('protobuf.js', () => {
5051
const buf = ProtobufjsTest.encode(message).finish()
5152
const result = ProtobufjsTest.decode(buf)
5253

5354
expectDecodedCorrectly(result)
5455
})
56+
.add('@protobuf-ts', () => {
57+
const buf = ProtobufTsTest.toBinary(message)
58+
const result = ProtobufTsTest.fromBinary(buf)
59+
60+
expectDecodedCorrectly(result)
61+
})
5562
.on('error', (err: Error) => {
5663
console.error(err)
5764
})

0 commit comments

Comments
 (0)