|
| 1 | +/* eslint-disable no-console */ |
1 | 2 |
|
2 |
| -import benny from 'benny' |
| 3 | +/* |
| 4 | +$ node dist/src/index.js |
| 5 | +$ npx playwright-test dist/src/index.js --runner benchmark |
| 6 | +*/ |
| 7 | + |
| 8 | +import Benchmark from 'benchmark' |
3 | 9 | import { expect } from 'aegir/chai'
|
4 | 10 | import { Test as ProtonsTest } from './protons/bench.js'
|
5 | 11 | import { encodeTest as pbjsEncodeTest, decodeTest as pbjsDecodeTest } from './pbjs/bench.js'
|
@@ -27,30 +33,34 @@ function expectDecodedCorrectly (result: any) {
|
27 | 33 | expect(result).to.have.property('payload').that.equalBytes(message.payload)
|
28 | 34 | }
|
29 | 35 |
|
30 |
| -void benny.suite( |
31 |
| - 'Encode/Decode', |
32 |
| - |
33 |
| - benny.add('pbjs', () => { |
| 36 | +new Benchmark.Suite() |
| 37 | + .add('pbjs', () => { |
34 | 38 | const buf = pbjsEncodeTest(message)
|
35 | 39 | const result = pbjsDecodeTest(buf)
|
36 | 40 |
|
37 | 41 | expectDecodedCorrectly(result)
|
38 |
| - }), |
39 |
| - |
40 |
| - benny.add('protons', () => { |
| 42 | + }) |
| 43 | + .add('protons', () => { |
41 | 44 | const buf = ProtonsTest.encode(message)
|
42 | 45 | const result = ProtonsTest.decode(buf)
|
43 | 46 |
|
44 | 47 | expectDecodedCorrectly(result)
|
45 |
| - }), |
46 |
| - |
47 |
| - benny.add('protobufjs', () => { |
| 48 | + }) |
| 49 | + .add('protobufjs', () => { |
48 | 50 | const buf = ProtobufjsTest.encode(message).finish()
|
49 | 51 | const result = ProtobufjsTest.decode(buf)
|
50 | 52 |
|
51 | 53 | expectDecodedCorrectly(result)
|
52 |
| - }), |
53 |
| - |
54 |
| - benny.cycle(), |
55 |
| - benny.complete() |
56 |
| -) |
| 54 | + }) |
| 55 | + .on('error', (err: Error) => { |
| 56 | + console.error(err) |
| 57 | + }) |
| 58 | + .on('cycle', (event: any) => { |
| 59 | + console.info(String(event.target)) |
| 60 | + }) |
| 61 | + .on('complete', function () { |
| 62 | + // @ts-expect-error types are wrong |
| 63 | + console.info(`Fastest is ${this.filter('fastest').map('name')}`) // eslint-disable-line @typescript-eslint/restrict-template-expressions |
| 64 | + }) |
| 65 | + // run async |
| 66 | + .run({ async: true }) |
0 commit comments