Skip to content

Commit

Permalink
chore: add protobuf-ts to benchmarks (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Oct 12, 2022
1 parent b1316fa commit 559191d
Show file tree
Hide file tree
Showing 8 changed files with 634 additions and 227 deletions.
41 changes: 30 additions & 11 deletions packages/protons-benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,40 @@ Run the benchmark suite:
```console
$ npm start

Running "Encode/Decode" suite...
Progress: 100%
> [email protected] prestart
> npm run build

pbjs:
12 166 ops/s, ±3.92% | 5.12% slower

protons:
9 755 ops/s, ±2.19% | slowest, 23.93% slower
> protons[email protected] build
> aegir build --no-bundle && cp -R src/protobufjs dist/src/protobufjs

protobufjs:
12 823 ops/s, ±2.02% | fastest
[15:02:28] tsc [started]
[15:02:32] tsc [completed]

Finished 3 cases!
Fastest: protobufjs
Slowest: protons
> [email protected] start
> node dist/src/index.js

pbjs x 11,798 ops/sec ±4.58% (88 runs sampled)
protons x 11,693 ops/sec ±2.69% (85 runs sampled)
protobuf.js x 12,419 ops/sec ±1.66% (88 runs sampled)
@protobuf-ts x 10,536 ops/sec ±3.14% (85 runs sampled)
Fastest is protobuf.js
```

Or in a browser:

```console
$ npm run start:browser

> [email protected] start:browser
> npx playwright-test dist/src/index.js --runner benchmark

✔ chromium set up
pbjs x 19,027 ops/sec ±0.86% (67 runs sampled)
protons x 18,901 ops/sec ±0.65% (67 runs sampled)
protobuf.js x 18,937 ops/sec ±0.55% (65 runs sampled)
@protobuf-ts x 16,669 ops/sec ±0.49% (68 runs sampled)
Fastest is pbjs,protobuf.js
```

## License
Expand Down
6 changes: 5 additions & 1 deletion packages/protons-benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
},
"ignorePatterns": [
"src/pbjs/*",
"src/protobuf-ts/*",
"src/protobufjs/*"
]
},
Expand All @@ -65,9 +66,12 @@
"dep-check": "aegir dep-check",
"build": "aegir build --no-bundle && cp -R src/protobufjs dist/src/protobufjs",
"prestart": "npm run build",
"start": "node dist/src/index.js"
"start": "node dist/src/index.js",
"start:browser": "npx playwright-test dist/src/index.js --runner benchmark"
},
"dependencies": {
"@protobuf-ts/plugin": "^2.8.1",
"@protobuf-ts/runtime": "^2.8.1",
"@types/benchmark": "^2.1.1",
"aegir": "^37.0.5",
"benchmark": "^2.1.4",
Expand Down
3 changes: 2 additions & 1 deletion packages/protons-benchmark/src/bench.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ message Bar {
}

enum FOO {
NONE=0;
LOL=1;
ABE=3;
}
Expand All @@ -19,7 +20,7 @@ message Yo {

message Lol {
optional string lol = 1;
required Bar b = 2;
Bar b = 2;
}

message Test {
Expand Down
9 changes: 8 additions & 1 deletion packages/protons-benchmark/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { expect } from 'aegir/chai'
import { Test as ProtonsTest } from './protons/bench.js'
import { encodeTest as pbjsEncodeTest, decodeTest as pbjsDecodeTest } from './pbjs/bench.js'
import { Test as ProtobufjsTest } from './protobufjs/bench.js'
import { Test as ProtobufTsTest } from './protobuf-ts/bench.js'

const message = {
meh: {
Expand Down Expand Up @@ -46,12 +47,18 @@ new Benchmark.Suite()

expectDecodedCorrectly(result)
})
.add('protobufjs', () => {
.add('protobuf.js', () => {
const buf = ProtobufjsTest.encode(message).finish()
const result = ProtobufjsTest.decode(buf)

expectDecodedCorrectly(result)
})
.add('@protobuf-ts', () => {
const buf = ProtobufTsTest.toBinary(message)
const result = ProtobufTsTest.fromBinary(buf)

expectDecodedCorrectly(result)
})
.on('error', (err: Error) => {
console.error(err)
})
Expand Down
Loading

0 comments on commit 559191d

Please sign in to comment.