-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/beacon-node/test/perf/network/gossip/fastMsgIdFn.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {randomBytes} from "node:crypto"; | ||
import xxhashFactory from "xxhash-wasm"; | ||
import {itBench} from "@dapplion/benchmark"; | ||
import {digest} from "@chainsafe/as-sha256"; | ||
|
||
const hasher = await xxhashFactory(); | ||
|
||
// Ethereum mainnet case processes 500_000 attestations / epoch (384 sec) = 1302 msg per sec | ||
|
||
describe("network / gossip / fastMsgIdFn", () => { | ||
const h32Seed = Math.floor(Math.random() * 1e9); | ||
const h64Seed = BigInt(Math.floor(Math.random() * 1e9)); | ||
for (const msgLen of [200, 1000, 10000]) { | ||
const msgData = randomBytes(msgLen); | ||
|
||
itBench({ | ||
id: `fastMsgIdFn sha256 / ${msgLen} bytes`, | ||
fn: () => { | ||
Buffer.from(digest(msgData)).subarray(0, 8).toString("hex"); | ||
}, | ||
}); | ||
|
||
itBench({ | ||
id: `fastMsgIdFn h32 xxhash / ${msgLen} bytes`, | ||
fn: () => { | ||
hasher.h32Raw(msgData, h32Seed); | ||
}, | ||
}); | ||
|
||
itBench({ | ||
id: `fastMsgIdFn h64 xxhash / ${msgLen} bytes`, | ||
fn: () => { | ||
hasher.h64Raw(msgData, h64Seed).toString(16); | ||
}, | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters