Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update the benchmark dependencies #429

Merged
merged 26 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cb112c4
Update the benchmark dependencies
nazarhussain Jan 10, 2025
c81b7d4
Fix lint error
nazarhussain Jan 10, 2025
da9049c
Fix the benchmark files
nazarhussain Jan 13, 2025
f80a3e6
Update the benchmark version
nazarhussain Jan 13, 2025
65c6516
Remove dead code
nazarhussain Jan 13, 2025
c855577
Update package version
nazarhussain Jan 13, 2025
072e47b
Update package version
nazarhussain Jan 13, 2025
ba7ae16
Test the hasher for performance regression
nazarhussain Jan 14, 2025
c9be823
Revert "Test the hasher for performance regression"
nazarhussain Jan 14, 2025
6f96c50
Update the package version
nazarhussain Jan 14, 2025
7632f54
Update the rc version of benchmark
nazarhussain Jan 14, 2025
bfe1ddd
Update the benchmark version
nazarhussain Jan 14, 2025
e2d4fb6
Sort the benchmarks
nazarhussain Jan 14, 2025
955bf5f
Update the benchmark rc file
nazarhussain Jan 15, 2025
c0dcf4b
Celanup GC
nazarhussain Jan 15, 2025
3c08473
Disable hasher to test
nazarhussain Jan 15, 2025
164d920
Disable hasher to test
nazarhussain Jan 15, 2025
80e8357
Revert hasher change
nazarhussain Jan 15, 2025
7989235
Update the setup file to include a hook
nazarhussain Jan 16, 2025
cfc0721
Update the sethasher loging
nazarhussain Jan 16, 2025
698a356
Update the benchmark lib version
nazarhussain Jan 16, 2025
1cf85ee
Cleanup the hasher
nazarhussain Jan 16, 2025
e258332
Bump package version
nazarhussain Jan 16, 2025
68d8ab1
Remove gc flag
nazarhussain Jan 16, 2025
9c20000
fix(persistent-ts): empty commit to trigger release from package.json…
matthewkeil Jan 17, 2025
bf5581a
fix(ssz): empty commit to trigger release from package.json fix
matthewkeil Jan 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .benchrc.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Mocha opts
colors: true
require:
- ts-node/register
- setHasher.mjs

# benchmark opts
threshold: 3
maxMs: 60_000
maxMs: 60000
minRuns: 10
triggerGC: false
sort: true
matthewkeil marked this conversation as resolved.
Show resolved Hide resolved
setupFiles:
- ./setHasher.mjs
4 changes: 0 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module.exports = {
browser: true,
es6: true,
node: true,
mocha: true,
},
globals: {
BigInt: true,
Expand Down Expand Up @@ -79,9 +78,6 @@ module.exports = {
quotes: ["error", "double"],
semi: "off",

// Prevents accidentally pushing a commit with .only in Mocha tests
"no-only-tests/no-only-tests": "error",

// TEMP Disabled while eslint-plugin-import support ESM (Typescript does support it) https://github.com/import-js/eslint-plugin-import/issues/2170
"import/no-unresolved": "off",
},
Expand Down
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.14.5",
"@babel/register": "^7.15.3",
"@dapplion/benchmark": "^0.2.2",
"@types/chai": "^4.2.15",
"@types/mocha": "^8.2.2",
"@chainsafe/benchmark": "^1.1.0",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^6",
"@typescript-eslint/parser": "^6",
Expand All @@ -41,7 +39,6 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"lerna": "^8.1.3",
"mocha": "^9.0.1",
"prettier": "^2.2.1",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
Expand All @@ -54,7 +51,6 @@
"webpack-dev-server": "^3.11.2"
},
"resolutions": {
"@types/react": "^17.0",
"chai": "4.5.0"
"@types/react": "^17.0"
matthewkeil marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
3 changes: 1 addition & 2 deletions packages/as-sha256/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
},
"devDependencies": {
"@chainsafe/babel-plugin-inline-binary-import": "^1.0.3",
"assemblyscript": "^0.27.24",
"benchmark": "^2.1.4"
"assemblyscript": "^0.27.24"
}
}
16 changes: 8 additions & 8 deletions packages/as-sha256/test/perf/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {itBench, setBenchOpts} from "@dapplion/benchmark";
import {bench, describe, setBenchOpts} from "@chainsafe/benchmark";
import {
digest,
digest2Bytes32,
Expand Down Expand Up @@ -26,15 +26,15 @@ describe("digestTwoHashObjects vs digest64 vs digest", () => {
const obj2 = byteArrayToHashObject(buffer2, 0);
// total number of time running hash for 200000 balances
const iterations = 50023;
itBench(`digestTwoHashObjects ${iterations} times`, () => {
bench(`digestTwoHashObjects ${iterations} times`, () => {
for (let j = 0; j < iterations; j++) digest64HashObjects(obj1, obj2);
});

itBench(`digest2Bytes32 ${iterations} times`, () => {
bench(`digest2Bytes32 ${iterations} times`, () => {
for (let j = 0; j < iterations; j++) digest2Bytes32(buffer1, buffer2);
});

itBench(`digest ${iterations} times`, () => {
bench(`digest ${iterations} times`, () => {
for (let j = 0; j < iterations; j++) digest(input);
});
});
Expand All @@ -45,7 +45,7 @@ describe("digest different Buffers", () => {

for (const length of [32, 64, 128, 256, 512, 1024]) {
const buffer = randomBuffer(length);
itBench(`input length ${length}`, () => {
bench(`input length ${length}`, () => {
digest(buffer);
});
}
Expand All @@ -64,7 +64,7 @@ describe("hash - compare to java", () => {
const iterations = 1000000;
const input = Buffer.from("lwkjt23uy45pojsdf;lnwo45y23po5i;lknwe;lknasdflnqw3uo5", "utf8");

itBench(`digest ${iterations} times`, () => {
bench(`digest ${iterations} times`, () => {
for (let i = 0; i < iterations; i++) digest(input);
});
});
Expand All @@ -81,12 +81,12 @@ describe("utils", () => {
// total number of time running hash for 200000 balances
const iterations = 50023;

itBench(`hashObjectToByteArray ${iterations} times`, () => {
bench(`hashObjectToByteArray ${iterations} times`, () => {
const byteArr = new Uint8Array(32);
for (let j = 0; j < iterations; j++) hashObjectToByteArray(obj1, byteArr, 0);
});

itBench(`byteArrayToHashObject ${iterations} times`, () => {
bench(`byteArrayToHashObject ${iterations} times`, () => {
for (let j = 0; j < iterations; j++) byteArrayToHashObject(buffer1, 0);
});
});
12 changes: 5 additions & 7 deletions packages/as-sha256/test/perf/simd.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {itBench, setBenchOpts} from "@dapplion/benchmark";
import {bench, describe, setBenchOpts} from "@chainsafe/benchmark";
import {batchHash4HashObjectInputs, batchHash4UintArray64s, digest64, digest64HashObjects} from "../../src/index.js";
import {byteArrayToHashObject} from "../../src/hashObject.js";

Expand All @@ -12,34 +12,32 @@ import {byteArrayToHashObject} from "../../src/hashObject.js";
✓ hash 200092 times using batchHash4HashObjectInputs 9.211751 ops/s 108.5570 ms/op - 88 runs 10.1 s
*/
describe("digest64 vs batchHash4UintArray64s vs digest64HashObjects vs batchHash4HashObjectInputs", function () {
this.timeout(0);

setBenchOpts({
minMs: 10_000,
});

const input = Buffer.from("gajindergajindergajindergajindergajindergajindergajindergajinder", "utf8");
// total number of time running hash for 200000 balances
const iterations = 50023;
itBench(`digest64 ${iterations * 4} times`, () => {
bench(`digest64 ${iterations * 4} times`, () => {
for (let j = 0; j < iterations * 4; j++) digest64(input);
});

// batchHash4UintArray64s do 4 sha256 in parallel
itBench(`hash ${iterations * 4} times using batchHash4UintArray64s`, () => {
bench(`hash ${iterations * 4} times using batchHash4UintArray64s`, () => {
for (let j = 0; j < iterations; j++) {
batchHash4UintArray64s([input, input, input, input]);
}
});

const hashObject = byteArrayToHashObject(Buffer.from("gajindergajindergajindergajinder", "utf8"), 0);
itBench(`digest64HashObjects ${iterations * 4} times`, () => {
bench(`digest64HashObjects ${iterations * 4} times`, () => {
for (let j = 0; j < iterations * 4; j++) digest64HashObjects(hashObject, hashObject);
});

const hashInputs = Array.from({length: 8}, () => hashObject);
// batchHash4HashObjectInputs do 4 sha256 in parallel
itBench(`hash ${iterations * 4} times using batchHash4HashObjectInputs`, () => {
bench(`hash ${iterations * 4} times using batchHash4HashObjectInputs`, () => {
for (let j = 0; j < iterations; j++) {
batchHash4HashObjectInputs(hashInputs);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/persistent-merkle-tree/test/perf/gindex.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {itBench} from "@dapplion/benchmark";
import {describe, bench} from "@chainsafe/benchmark";
import {getGindexBits, getGindicesAtDepth, gindexIterator, iterateAtDepth} from "../../src/index.js";

describe("gindices at depth", () => {
Expand All @@ -9,14 +9,14 @@ describe("gindices at depth", () => {
// ✓ getGindicesAtDepth 188146.8 ops/s 5.315000 us/op x0.587 1788863 runs 10.1 s
// ✓ iterateAtDepth 89047.20 ops/s 11.23000 us/op x0.977 867266 runs 10.0 s

itBench("getGindicesAtDepth", () => {
bench("getGindicesAtDepth", () => {
const gindices = getGindicesAtDepth(depth, startIx, count);
for (let i = 0; i < gindices.length; i++) {
//
}
});

itBench("iterateAtDepth", () => {
bench("iterateAtDepth", () => {
for (let gindex of iterateAtDepth(depth, BigInt(startIx), BigInt(count))) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
gindex++;
Expand All @@ -30,14 +30,14 @@ describe("gindex bits", () => {
// ✓ getGindexBits 1381215 ops/s 724.0000 ns/op - 9967639 runs 10.6 s
// ✓ gindexIterator 801282.1 ops/s 1.248000 us/op - 6466357 runs 10.2 s

itBench("getGindexBits", () => {
bench("getGindexBits", () => {
const bits = getGindexBits(gindex);
for (let i = 0; i < bits.length; i++) {
!!bits[i];
}
});

itBench("gindexIterator", () => {
bench("gindexIterator", () => {
for (const bit of gindexIterator(gindex)) {
!!bit;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {itBench} from "@dapplion/benchmark";
import { HashComputation, HashComputationLevel, LeafNode, zeroHash } from "../../src/index.js";
import {describe, bench} from "@chainsafe/benchmark";
import {HashComputation, HashComputationLevel, LeafNode, zeroHash} from "../../src/index.js";

/**
* HashComputationLevel push then loop is faster than HashComputation[] push then loop
Expand All @@ -15,7 +15,7 @@ describe("HashComputationLevel", function () {

const length = 2_000_000;

itBench({
bench({
id: "HashComputationLevel.push then loop",
before: () => new HashComputationLevel(),
beforeEach: (level) => {
Expand All @@ -30,10 +30,10 @@ describe("HashComputationLevel", function () {
for (const hc of level) {
const {src0, src1, dest} = hc;
}
}
},
});

itBench({
bench({
id: "HashComputation[] push then loop",
fn: () => {
const level: HashComputation[] = [];
Expand All @@ -43,6 +43,6 @@ describe("HashComputationLevel", function () {
for (const hc of level) {
const {src0, src1, dest} = hc;
}
}
})
},
});
});
16 changes: 7 additions & 9 deletions packages/persistent-merkle-tree/test/perf/hasher.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {itBench} from "@dapplion/benchmark";
import {describe, bench} from "@chainsafe/benchmark";
import {Hasher, HashObject, setHasher, uint8ArrayToHashObject} from "../../src/hasher/index.js";
import {hasher as asSha256Hasher} from "../../src/hasher/as-sha256.js";
import {hasher as nobleHasher} from "../../src/hasher/noble.js";
Expand All @@ -7,8 +7,6 @@ import {buildComparisonTrees} from "../utils/tree.js";
import {HashComputationLevel, getHashComputations} from "../../src/index.js";

describe("hasher", function () {
this.timeout(0);

const iterations = 500_000;

const root1 = new Uint8Array(32);
Expand All @@ -25,7 +23,7 @@ describe("hasher", function () {
const runsFactor = 10;
for (const hasher of hashers) {
describe(hasher.name, () => {
itBench({
bench({
id: `hash 2 Uint8Array ${iterations} times - ${hasher.name}`,
fn: () => {
for (let i = 0; i < runsFactor; i++) {
Expand All @@ -35,7 +33,7 @@ describe("hasher", function () {
runsFactor,
});

itBench({
bench({
id: `hashTwoObjects ${iterations} times - ${hasher.name}`,
before: () => ({
obj1: uint8ArrayToHashObject(root1),
Expand All @@ -51,7 +49,7 @@ describe("hasher", function () {
runsFactor,
});

itBench({
bench({
id: `executeHashComputations - ${hasher.name}`,
beforeEach: () => {
const [tree] = buildComparisonTrees(16);
Expand All @@ -68,7 +66,7 @@ describe("hasher", function () {
});

describe("hashtree", function () {
itBench({
bench({
id: "getHashComputations",
beforeEach: () => {
const [tree] = buildComparisonTrees(16);
Expand All @@ -80,7 +78,7 @@ describe("hashtree", function () {
},
});

itBench({
bench({
id: "executeHashComputations",
beforeEach: () => {
const [tree] = buildComparisonTrees(16);
Expand All @@ -93,7 +91,7 @@ describe("hashtree", function () {
},
});

itBench({
bench({
id: "get root",
beforeEach: async () => {
const [tree] = buildComparisonTrees(16);
Expand Down
18 changes: 9 additions & 9 deletions packages/persistent-merkle-tree/test/perf/node.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {itBench} from "@dapplion/benchmark";
import {describe, bench} from "@chainsafe/benchmark";
import {BranchNode, getNodeH, LeafNode} from "../../src/node.js";
import {countToDepth, getHashComputations, subtreeFillToContents} from "../../src/index.js";
import {batchHash} from "../utils/batchHash.js";
Expand All @@ -9,19 +9,19 @@ describe("HashObject LeafNode", () => {

const zeroLeafNode = LeafNode.fromZero();

itBench(`getNodeH() x${nodesPerSlot} avg hindex`, () => {
bench(`getNodeH() x${nodesPerSlot} avg hindex`, () => {
for (let i = 0; i < nodesPerSlot; i++) {
getNodeH(zeroLeafNode, i % 8);
}
});

itBench(`getNodeH() x${nodesPerSlot} index 0`, () => {
bench(`getNodeH() x${nodesPerSlot} index 0`, () => {
for (let i = 0; i < nodesPerSlot; i++) {
getNodeH(zeroLeafNode, 0);
}
});

itBench(`getNodeH() x${nodesPerSlot} index 7`, () => {
bench(`getNodeH() x${nodesPerSlot} index 7`, () => {
for (let i = 0; i < nodesPerSlot; i++) {
getNodeH(zeroLeafNode, 7);
}
Expand All @@ -30,13 +30,13 @@ describe("HashObject LeafNode", () => {
// As fast as previous methods
const keys: (keyof LeafNode)[] = ["h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7"];

itBench(`getNodeH() x${nodesPerSlot} index 7 with key array`, () => {
bench(`getNodeH() x${nodesPerSlot} index 7 with key array`, () => {
for (let i = 0; i < nodesPerSlot; i++) {
zeroLeafNode[keys[7]];
}
});

itBench(`new LeafNode() x${nodesPerSlot}`, () => {
bench(`new LeafNode() x${nodesPerSlot}`, () => {
for (let i = 0; i < nodesPerSlot; i++) {
LeafNode.fromHashObject(zeroLeafNode);
}
Expand All @@ -47,23 +47,23 @@ describe("Node batchHash", () => {
const numNodes = [250_000, 500_000, 1_000_000];

for (const numNode of numNodes) {
itBench({
bench({
id: `getHashComputations ${numNode} nodes`,
beforeEach: () => createList(numNode),
fn: (rootNode: BranchNode) => {
getHashComputations(rootNode, 0, []);
},
});

itBench({
bench({
id: `batchHash ${numNode} nodes`,
beforeEach: () => createList(numNode),
fn: (rootNode: BranchNode) => {
batchHash(rootNode);
},
});

itBench({
bench({
id: `get root ${numNode} nodes`,
beforeEach: () => createList(numNode),
fn: (rootNode: BranchNode) => {
Expand Down
Loading
Loading