Skip to content

Commit

Permalink
Update the benchmark dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Jan 10, 2025
1 parent 5868113 commit eed65e3
Show file tree
Hide file tree
Showing 45 changed files with 465 additions and 619 deletions.
6 changes: 0 additions & 6 deletions .benchrc.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Mocha opts
colors: true
require:
- ts-node/register
- setHasher.mjs

# benchmark opts
threshold: 3
maxMs: 60_000
Expand Down
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
8 changes: 2 additions & 6 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-rc.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"
}
}
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, setBenchOpts} from "@chainsafe/benchmark";
import * as sha256 from "../../src/index.js";

// Feb 2024 Mac M1
Expand All @@ -20,15 +20,15 @@ describe("digestTwoHashObjects vs digest64 vs digest", () => {
const obj2 = sha256.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++) sha256.digest64HashObjects(obj1, obj2);
});

itBench(`digest64 ${iterations} times`, () => {
bench(`digest64 ${iterations} times`, () => {
for (let j = 0; j < iterations; j++) sha256.digest64(input);
});

itBench(`digest ${iterations} times`, () => {
bench(`digest ${iterations} times`, () => {
for (let j = 0; j < iterations; j++) sha256.digest(input);
});
});
Expand All @@ -39,7 +39,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}`, () => {
sha256.digest(buffer);
});
}
Expand All @@ -59,7 +59,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++) sha256.digest(input);
});
});
Expand All @@ -76,12 +76,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++) sha256.hashObjectToByteArray(obj1, byteArr, 0);
});

itBench(`byteArrayToHashObject ${iterations} times`, () => {
bench(`byteArrayToHashObject ${iterations} times`, () => {
for (let j = 0; j < iterations; j++) sha256.byteArrayToHashObject(buffer1, 0);
});
});
10 changes: 5 additions & 5 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, setBenchOpts} from "@chainsafe/benchmark";
import * as sha256 from "../../src/index.js";
import {byteArrayToHashObject} from "../../src/hashObject.js";

Expand All @@ -21,25 +21,25 @@ describe("digest64 vs batchHash4UintArray64s vs digest64HashObjects vs batchHash
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++) sha256.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++) {
sha256.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++) sha256.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++) {
sha256.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,4 +1,4 @@
import {itBench} from "@dapplion/benchmark";
import {describe, bench} from "@chainsafe/benchmark";
import { HashComputation, HashComputationLevel, LeafNode, zeroHash } from "../../src/index.js";

/**
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 @@ -33,7 +33,7 @@ describe("HashComputationLevel", function () {
}
});

itBench({
bench({
id: "HashComputation[] push then loop",
fn: () => {
const level: HashComputation[] = [];
Expand Down
24 changes: 11 additions & 13 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 {HashObject, setHasher, uint8ArrayToHashObject} from "../../src/hasher/index.js";
import {hasher as asShaHasher} 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 @@ -23,7 +21,7 @@ describe("hasher", function () {
const runsFactor = 10;
for (const hasher of [asShaHasher, nobleHasher, hashtreeHasher]) {
describe(hasher.name, () => {
itBench({
bench({
id: `hash 2 Uint8Array ${iterations} times - ${hasher.name}`,
fn: () => {
for (let i = 0; i < runsFactor; i++) {
Expand All @@ -33,7 +31,7 @@ describe("hasher", function () {
runsFactor,
});

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

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

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

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

itBench({
id: `get root`,
bench({
id: "get root",
beforeEach: () => {
const [tree] = buildComparisonTrees(16);
setHasher(hashtreeHasher);
return tree;
},
fn: (tree) => {
tree.root;
tree.root;
},
});
});
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

0 comments on commit eed65e3

Please sign in to comment.