Skip to content

Commit

Permalink
test: add batchHash perf comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewkeil committed Jun 11, 2024
1 parent 037715b commit 7c74382
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/persistent-merkle-tree/test/perf/hasher.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import {itBench} from "@dapplion/benchmark";
import {uint8ArrayToHashObject} from "../../src/hasher";
import {HashObject, uint8ArrayToHashObject} from "../../src/hasher";
import {hasher as asShaHasher} from "../../src/hasher/as-sha256";
import {hasher as nobleHasher} from "../../src/hasher/noble";
import {hasher as hashtreeHasher} from "../../src/hasher/hashtree";
import {buildComparisonTrees} from "../utils/tree";

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

// total number of time running hash for 250_000 validators
// const iterations = 2_250_026;
const iterations = 1_000_000;

const root1 = new Uint8Array(32);
const root2 = new Uint8Array(32);
for (let i = 0; i < root1.length; i++) {
Expand All @@ -18,9 +23,11 @@ describe("hasher", function () {

const [tree] = buildComparisonTrees(16);

// total number of time running hash for 250_000 validators
// const iterations = 2_250_026;
const iterations = 1_000_000;
const hashObjects: HashObject[] = [];
for (let i = 0; i < iterations; i++) {
hashObjects.push(uint8ArrayToHashObject(root1));
hashObjects.push(uint8ArrayToHashObject(root2));
}

for (const hasher of [asShaHasher, nobleHasher, hashtreeHasher]) {
describe(hasher.name, () => {
Expand All @@ -40,7 +47,12 @@ describe("hasher", function () {
},
});

// itBench(`batchHash - ${hasher.name}`, () => {});
itBench({
id: `batchHash - ${hasher.name}`,
fn: () => {
hasher.batchHashObjects(hashObjects);
},
});

itBench({
id: `executeHashComputations - ${hasher.name}`,
Expand Down

0 comments on commit 7c74382

Please sign in to comment.