Skip to content

Commit

Permalink
fix: fix benchmarking (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain committed Jan 11, 2024
1 parent e2befc7 commit da1461b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"devDependencies": {
"@chainsafe/eslint-plugin-node": "^11.2.3",
"@dapplion/benchmark": "^0.1.6",
"@dapplion/benchmark": "^0.2.4",
"@types/chai": "^4.2.0",
"@types/debug": "^4.1.5",
"@types/eslint": "^6.1.3",
Expand Down
10 changes: 10 additions & 0 deletions packages/enr/.bench.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Mocha opts
extension: ["ts"]
colors: true
node-option:
- "loader=ts-node/register"

# benchmark opts
# threshold: 3
# maxMs: 60_000
# minRuns: 10
25 changes: 20 additions & 5 deletions packages/enr/bench/index.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { itBench, setBenchOpts } from "@dapplion/benchmark";
import { itBench } from "@dapplion/benchmark";
import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
import {
ENR,
SignableENR,
createPeerIdFromPrivateKey,
createPeerIdFromPublicKey,
Expand All @@ -9,8 +10,6 @@ import {
} from "../src/index.js";

describe("ENR", async function () {
setBenchOpts({ runs: 50000 });

const peerId = await createSecp256k1PeerId();
const { privateKey } = createPrivateKeyFromPeerId(peerId);
const enr = SignableENR.createV4(privateKey);
Expand All @@ -26,8 +25,6 @@ describe("ENR", async function () {
});

describe("createPeerIdFromPrivateKey", async function () {
setBenchOpts({ runs: 4000 });

const peerId = await createSecp256k1PeerId();
const { type, privateKey } = createPrivateKeyFromPeerId(peerId);
const { publicKey } = createPublicKeyFromPeerId(peerId);
Expand All @@ -39,3 +36,21 @@ describe("createPeerIdFromPrivateKey", async function () {
return createPeerIdFromPublicKey(type, publicKey);
});
});

describe("ENR - encode/decode", async function () {
const peerId = await createSecp256k1PeerId();
const { privateKey } = createPrivateKeyFromPeerId(peerId);
const enr = SignableENR.createV4(privateKey);
enr.ip = "127.0.0.1";
enr.tcp = 8080;
enr.udp = 8080;

const encoded = enr.encode();

itBench("ENR - encode", () => {
return enr.encode();
});
itBench("ENR - decode", () => {
return ENR.decode(encoded);
});
});
1 change: 1 addition & 0 deletions packages/enr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"prepublishOnly": "yarn build",
"lint": "eslint --color --ext .ts src/ test/",
"test": "yarn test:unit && yarn test:e2e",
"test:perf": "NODE_OPTIONS='--max-old-space-size=4096 --loader=ts-node/esm' benchmark 'bench/**/*.bench.ts' --config .bench.yaml",
"test:unit": "mocha 'test/unit/**/*.test.ts'"
},
"pre-push": [
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -314,18 +314,18 @@
dependencies:
"@jridgewell/trace-mapping" "0.3.9"

"@dapplion/benchmark@^0.1.6":
version "0.1.6"
resolved "https://registry.yarnpkg.com/@dapplion/benchmark/-/benchmark-0.1.6.tgz#d58cc150732a2d743089b9462cdfef9339ef81fa"
integrity sha512-qBNXvktHxqnfql2dtjdYqPVj+6OZriuKYNB/ZOdZv58kov9/vEVxFstlXQKCnmxVgC3q4NNmvWXIemTAPZah/A==
"@dapplion/benchmark@^0.2.4":
version "0.2.4"
resolved "https://registry.yarnpkg.com/@dapplion/benchmark/-/benchmark-0.2.4.tgz#e75443a067af4c923c5c32c932750d297b3a34c0"
integrity sha512-57nIqyEEgEoSPzLTTgkt5NukLbZuYCg9lmNml+/QR4TcwwFugSuSPmNQTDKyqO92l8XmI8AfSxSoIioAXkJ7lw==
dependencies:
"@actions/cache" "^1.0.7"
"@actions/github" "^5.0.0"
ajv "^8.6.0"
aws-sdk "^2.932.0"
csv-parse "^4.16.0"
csv-stringify "^5.6.2"
yargs "^17.0.1"
yargs "^17.1.1"

"@eslint-community/eslint-utils@^4.2.0":
version "4.4.0"
Expand Down Expand Up @@ -6917,7 +6917,7 @@ yargs@^13.2.2:
y18n "^4.0.0"
yargs-parser "^13.1.2"

yargs@^17.0.1, yargs@^17.6.2:
yargs@^17.1.1, yargs@^17.6.2:
version "17.7.2"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269"
integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==
Expand Down

0 comments on commit da1461b

Please sign in to comment.