Skip to content

Commit

Permalink
chore: bechmark messages at different lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Oct 31, 2023
1 parent d408d27 commit b20e007
Showing 1 changed file with 45 additions and 36 deletions.
81 changes: 45 additions & 36 deletions test/benchmark/protobuf.test.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,59 @@
import crypto from 'node:crypto'
import { itBench, setBenchOpts } from '@dapplion/benchmark'
import { RPC } from '../../src/message/rpc.js'

describe('protobuf', function () {
this.timeout(0)
setBenchOpts({
maxMs: 200 * 1000,
minMs: 120 * 1000
minMs: 60 * 1000
})

const rpc: RPC = {
subscriptions: [],
messages: [
{
topic: 'topic1',
// typical Attestation
data: Buffer.from(
'e40000000a000000000000000a00000000000000a45c8daa336e17a150300afd4c717313c84f291754c51a378f20958083c5fa070a00000000000000a45c8daa336e17a150300afd4c717313c84f291754c51a378f20958083c5fa070a00000000000000a45c8daa336e17a150300afd4c717313c84f291754c51a378f20958083c5fa0795d2ef8ae4e2b4d1e5b3d5ce47b518e3db2c8c4d082e4498805ac2a686c69f248761b78437db2927470c1e77ede9c18606110faacbcbe4f13052bde7f7eff6aab09edf7bc4929fda2230f943aba2c47b6f940d350cb20c76fad4a8d40e2f3f1f01',
'hex'
),
signature: Uint8Array.from(Array.from({ length: 96 }, () => 100))
}
],
control: undefined
}
const testCases: { name: string; length: number }[] = [
// As of Oct 2023, Attestation length = 281
{ name: 'Attestation', length: 300 },
// A SignedBeaconBlock could be from 70_000 to 300_000
{ name: 'SignedBeaconBlock', length: 70_000 },
{ name: 'SignedBeaconBlock', length: 140_000 },
{ name: 'SignedBeaconBlock', length: 210_000 },
{ name: 'SignedBeaconBlock', length: 280_000 }
]

const bytes = RPC.encode(rpc)
for (const { name, length } of testCases) {
const rpc: RPC = {
subscriptions: [],
messages: [
{
topic: 'topic1',
data: crypto.randomBytes(length),
signature: Uint8Array.from(Array.from({ length: 96 }, () => 100))
}
],
control: undefined
}

const runsFactor = 1000
const bytes = RPC.encode(rpc)

itBench({
id: 'decode Attestation message using protons-runtime 5.1.0',
fn: () => {
for (let i = 0; i < runsFactor; i++) {
RPC.decode(bytes)
}
},
runsFactor
})
const runsFactor = 1000

itBench({
id: 'encode Attestation message using protons-runtime 5.1.0',
fn: () => {
for (let i = 0; i < runsFactor; i++) {
RPC.encode(rpc)
}
},
runsFactor
})
itBench({
id: `decode ${name} message ${length} bytes`,
fn: () => {
for (let i = 0; i < runsFactor; i++) {
RPC.decode(bytes)
}
},
runsFactor
})

itBench({
id: `encode ${name} message ${length} bytes`,
fn: () => {
for (let i = 0; i < runsFactor; i++) {
RPC.encode(rpc)
}
},
runsFactor
})
}
})

0 comments on commit b20e007

Please sign in to comment.