Skip to content

Commit 47a4dcb

Browse files
felicioachingbrain
andauthored
1 parent 47359ee commit 47a4dcb

File tree

4 files changed

+267
-15
lines changed

4 files changed

+267
-15
lines changed

packages/protons-benchmark/README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,17 @@
1717

1818
## Install
1919

20-
```console
21-
$ npm i protons-benchmark
22-
```
23-
2420
```console
2521
$ git clone [email protected]:ipfs/protons.git
2622
$ cd protons
2723
$ npm i
24+
$ npm run build
2825
$ cd packages/protons-benchmark
2926
```
3027

3128
## Usage
3229

33-
Run the benchmark suite:
30+
Run the benchmark suite in node:
3431

3532
```console
3633
$ npm start
@@ -48,10 +45,11 @@ $ npm start
4845
4946
> node dist/src/index.js
5047

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)
48+
pbjs x 19,188 ops/sec ±0.38% (98 runs sampled)
49+
protons x 19,001 ops/sec ±0.33% (95 runs sampled)
50+
protobuf.js x 19,558 ops/sec ±0.30% (91 runs sampled)
51+
@protobuf-ts x 17,216 ops/sec ±0.32% (95 runs sampled)
52+
protobuf-es x 15,673 ops/sec ±0.48% (93 runs sampled)
5553
Fastest is protobuf.js
5654
```
5755

@@ -64,11 +62,12 @@ $ npm run start:browser
6462
> npx playwright-test dist/src/index.js --runner benchmark
6563

6664
✔ 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
65+
pbjs x 19,763 ops/sec ±0.35% (67 runs sampled)
66+
protons x 19,617 ops/sec ±0.37% (68 runs sampled)
67+
protobuf.js x 19,772 ops/sec ±0.34% (67 runs sampled)
68+
@protobuf-ts x 17,204 ops/sec ±0.33% (69 runs sampled)
69+
protobuf-es x 16,032 ops/sec ±0.38% (68 runs sampled)
70+
Fastest is protobuf.js,pbjs
7271
```
7372

7473
## API Docs

packages/protons-benchmark/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,23 @@
3333
},
3434
"ignorePatterns": [
3535
"src/implementations/pbjs/*",
36+
"src/implementations/protobuf-es/*",
3637
"src/implementations/protobuf-ts/*",
3738
"src/implementations/protobufjs/*"
3839
]
3940
},
4041
"scripts": {
4142
"clean": "aegir clean",
4243
"lint": "aegir lint",
43-
"dep-check": "aegir dep-check --ignore @protobuf-ts/plugin pbjs protons",
44+
"dep-check": "aegir dep-check --ignore @protobuf-ts/plugin pbjs protons @bufbuild/protoc-gen-es",
4445
"build": "aegir build --no-bundle && cp -R src/implementations/protobufjs dist/src/implementations/protobufjs",
4546
"prestart": "npm run build",
4647
"start": "node dist/src/implementations/index.js",
4748
"start:browser": "npx playwright-test dist/src/implementations/index.js --runner benchmark"
4849
},
4950
"dependencies": {
51+
"@bufbuild/protobuf": "^1.0.0",
52+
"@bufbuild/protoc-gen-es": "^1.3.3",
5053
"@protobuf-ts/plugin": "^2.8.1",
5154
"@protobuf-ts/runtime": "^2.8.1",
5255
"@types/benchmark": "^2.1.1",

packages/protons-benchmark/src/implementations/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ $ npx playwright-test dist/src/index.js --runner benchmark
88
import { expect } from 'aegir/chai'
99
import Benchmark from 'benchmark'
1010
import { encodeTest as pbjsEncodeTest, decodeTest as pbjsDecodeTest } from './pbjs/bench.js'
11+
import { Test as ProtobufEsTest } from './protobuf-es/bench_pb.js'
1112
import { Test as ProtobufTsTest } from './protobuf-ts/bench.js'
1213
import { Test as ProtobufjsTest } from './protobufjs/bench.js'
1314
import { Test as ProtonsTest } from './protons/bench.js'
@@ -59,6 +60,12 @@ new Benchmark.Suite()
5960

6061
expectDecodedCorrectly(result)
6162
})
63+
.add('protobuf-es', () => {
64+
const buf = new ProtobufEsTest(message).toBinary()
65+
const result = ProtobufEsTest.fromBinary(buf)
66+
67+
expectDecodedCorrectly(result)
68+
})
6269
.on('error', (err: Error) => {
6370
console.error(err)
6471
})
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
// @generated by protoc-gen-es v1.0.0 with parameter "target=ts"
2+
// @generated from file bench.proto (syntax proto3)
3+
/* eslint-disable */
4+
// @ts-nocheck
5+
6+
import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
7+
import { Message, proto3 } from "@bufbuild/protobuf";
8+
9+
/**
10+
* @generated from enum FOO
11+
*/
12+
export enum FOO {
13+
/**
14+
* @generated from enum value: NONE = 0;
15+
*/
16+
NONE = 0,
17+
18+
/**
19+
* @generated from enum value: LOL = 1;
20+
*/
21+
LOL = 1,
22+
23+
/**
24+
* @generated from enum value: ABE = 3;
25+
*/
26+
ABE = 3,
27+
}
28+
// Retrieve enum metadata with: proto3.getEnumType(FOO)
29+
proto3.util.setEnumType(FOO, "FOO", [
30+
{ no: 0, name: "NONE" },
31+
{ no: 1, name: "LOL" },
32+
{ no: 3, name: "ABE" },
33+
]);
34+
35+
/**
36+
* @generated from message Foo
37+
*/
38+
export class Foo extends Message<Foo> {
39+
/**
40+
* @generated from field: optional uint32 baz = 1;
41+
*/
42+
baz?: number;
43+
44+
constructor(data?: PartialMessage<Foo>) {
45+
super();
46+
proto3.util.initPartial(data, this);
47+
}
48+
49+
static readonly runtime = proto3;
50+
static readonly typeName = "Foo";
51+
static readonly fields: FieldList = proto3.util.newFieldList(() => [
52+
{ no: 1, name: "baz", kind: "scalar", T: 13 /* ScalarType.UINT32 */, opt: true },
53+
]);
54+
55+
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Foo {
56+
return new Foo().fromBinary(bytes, options);
57+
}
58+
59+
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): Foo {
60+
return new Foo().fromJson(jsonValue, options);
61+
}
62+
63+
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): Foo {
64+
return new Foo().fromJsonString(jsonString, options);
65+
}
66+
67+
static equals(a: Foo | PlainMessage<Foo> | undefined, b: Foo | PlainMessage<Foo> | undefined): boolean {
68+
return proto3.util.equals(Foo, a, b);
69+
}
70+
}
71+
72+
/**
73+
* @generated from message Bar
74+
*/
75+
export class Bar extends Message<Bar> {
76+
/**
77+
* @generated from field: optional Foo tmp = 1;
78+
*/
79+
tmp?: Foo;
80+
81+
constructor(data?: PartialMessage<Bar>) {
82+
super();
83+
proto3.util.initPartial(data, this);
84+
}
85+
86+
static readonly runtime = proto3;
87+
static readonly typeName = "Bar";
88+
static readonly fields: FieldList = proto3.util.newFieldList(() => [
89+
{ no: 1, name: "tmp", kind: "message", T: Foo, opt: true },
90+
]);
91+
92+
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Bar {
93+
return new Bar().fromBinary(bytes, options);
94+
}
95+
96+
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): Bar {
97+
return new Bar().fromJson(jsonValue, options);
98+
}
99+
100+
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): Bar {
101+
return new Bar().fromJsonString(jsonString, options);
102+
}
103+
104+
static equals(a: Bar | PlainMessage<Bar> | undefined, b: Bar | PlainMessage<Bar> | undefined): boolean {
105+
return proto3.util.equals(Bar, a, b);
106+
}
107+
}
108+
109+
/**
110+
* @generated from message Yo
111+
*/
112+
export class Yo extends Message<Yo> {
113+
/**
114+
* @generated from field: repeated FOO lol = 1;
115+
*/
116+
lol: FOO[] = [];
117+
118+
constructor(data?: PartialMessage<Yo>) {
119+
super();
120+
proto3.util.initPartial(data, this);
121+
}
122+
123+
static readonly runtime = proto3;
124+
static readonly typeName = "Yo";
125+
static readonly fields: FieldList = proto3.util.newFieldList(() => [
126+
{ no: 1, name: "lol", kind: "enum", T: proto3.getEnumType(FOO), repeated: true },
127+
]);
128+
129+
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Yo {
130+
return new Yo().fromBinary(bytes, options);
131+
}
132+
133+
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): Yo {
134+
return new Yo().fromJson(jsonValue, options);
135+
}
136+
137+
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): Yo {
138+
return new Yo().fromJsonString(jsonString, options);
139+
}
140+
141+
static equals(a: Yo | PlainMessage<Yo> | undefined, b: Yo | PlainMessage<Yo> | undefined): boolean {
142+
return proto3.util.equals(Yo, a, b);
143+
}
144+
}
145+
146+
/**
147+
* @generated from message Lol
148+
*/
149+
export class Lol extends Message<Lol> {
150+
/**
151+
* @generated from field: optional string lol = 1;
152+
*/
153+
lol?: string;
154+
155+
/**
156+
* @generated from field: Bar b = 2;
157+
*/
158+
b?: Bar;
159+
160+
constructor(data?: PartialMessage<Lol>) {
161+
super();
162+
proto3.util.initPartial(data, this);
163+
}
164+
165+
static readonly runtime = proto3;
166+
static readonly typeName = "Lol";
167+
static readonly fields: FieldList = proto3.util.newFieldList(() => [
168+
{ no: 1, name: "lol", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
169+
{ no: 2, name: "b", kind: "message", T: Bar },
170+
]);
171+
172+
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Lol {
173+
return new Lol().fromBinary(bytes, options);
174+
}
175+
176+
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): Lol {
177+
return new Lol().fromJson(jsonValue, options);
178+
}
179+
180+
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): Lol {
181+
return new Lol().fromJsonString(jsonString, options);
182+
}
183+
184+
static equals(a: Lol | PlainMessage<Lol> | undefined, b: Lol | PlainMessage<Lol> | undefined): boolean {
185+
return proto3.util.equals(Lol, a, b);
186+
}
187+
}
188+
189+
/**
190+
* @generated from message Test
191+
*/
192+
export class Test extends Message<Test> {
193+
/**
194+
* @generated from field: optional Lol meh = 6;
195+
*/
196+
meh?: Lol;
197+
198+
/**
199+
* @generated from field: optional uint32 hello = 3;
200+
*/
201+
hello?: number;
202+
203+
/**
204+
* @generated from field: optional string foo = 1;
205+
*/
206+
foo?: string;
207+
208+
/**
209+
* @generated from field: optional bytes payload = 7;
210+
*/
211+
payload?: Uint8Array;
212+
213+
constructor(data?: PartialMessage<Test>) {
214+
super();
215+
proto3.util.initPartial(data, this);
216+
}
217+
218+
static readonly runtime = proto3;
219+
static readonly typeName = "Test";
220+
static readonly fields: FieldList = proto3.util.newFieldList(() => [
221+
{ no: 6, name: "meh", kind: "message", T: Lol, opt: true },
222+
{ no: 3, name: "hello", kind: "scalar", T: 13 /* ScalarType.UINT32 */, opt: true },
223+
{ no: 1, name: "foo", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
224+
{ no: 7, name: "payload", kind: "scalar", T: 12 /* ScalarType.BYTES */, opt: true },
225+
]);
226+
227+
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Test {
228+
return new Test().fromBinary(bytes, options);
229+
}
230+
231+
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): Test {
232+
return new Test().fromJson(jsonValue, options);
233+
}
234+
235+
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): Test {
236+
return new Test().fromJsonString(jsonString, options);
237+
}
238+
239+
static equals(a: Test | PlainMessage<Test> | undefined, b: Test | PlainMessage<Test> | undefined): boolean {
240+
return proto3.util.equals(Test, a, b);
241+
}
242+
}
243+

0 commit comments

Comments
 (0)