Skip to content

Commit

Permalink
test: migrate utils tests to vitest (#6225)
Browse files Browse the repository at this point in the history
* Migrate utils tests to vitest

* Remove e2e test script
  • Loading branch information
nazarhussain authored Dec 21, 2023
1 parent 7b6e3f7 commit ae04197
Show file tree
Hide file tree
Showing 22 changed files with 152 additions and 168 deletions.
3 changes: 0 additions & 3 deletions packages/utils/.mocharc.yml

This file was deleted.

9 changes: 0 additions & 9 deletions packages/utils/karma.config.cjs

This file was deleted.

7 changes: 5 additions & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
"lint": "eslint --color --ext .ts src/ test/",
"lint:fix": "yarn run lint --fix",
"pretest": "yarn run check-types",
"test:unit": "mocha 'test/**/*.test.ts'",
"test:browsers": "yarn karma start karma.config.cjs",
"test:unit": "vitest --run --dir test/unit/ --coverage",
"test:browsers": "yarn test:browsers:chrome && yarn test:browsers:firefox && yarn test:browsers:electron",
"test:browsers:chrome": "vitest --run --browser chrome --config ./vitest.browser.config.ts --dir test/unit",
"test:browsers:firefox": "vitest --run --browser firefox --config ./vitest.browser.config.ts --dir test/unit",
"test:browsers:electron": "echo 'Electron tests will be introduced back in the future as soon vitest supports electron.'",
"check-readme": "typescript-docs-verifier"
},
"types": "lib/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions packages/utils/test/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export async function setup(): Promise<void> {}
export async function teardown(): Promise<void> {}
6 changes: 0 additions & 6 deletions packages/utils/test/setup.ts

This file was deleted.

15 changes: 7 additions & 8 deletions packages/utils/test/unit/assert.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import "../setup.js";
import {expect} from "chai";
import {describe, it, expect} from "vitest";
import {assert} from "../../src/index.js";

describe("assert", () => {
describe("true", () => {
it("Should not throw with true", () => {
expect(() => assert.true(true)).to.not.throw();
expect(() => assert.true(true)).not.toThrow();
});
it("Should throw with false", () => {
expect(() => assert.true(false, "something must be valid")).to.throw("something must be valid");
expect(() => assert.true(false, "something must be valid")).toThrow("something must be valid");
});
});

describe("equal with custom message", () => {
it("Should not throw with equal values", () => {
expect(() => assert.equal(1, 1)).to.not.throw();
expect(() => assert.equal(1, 1)).not.toThrow();
});
it("Should throw with different values", () => {
expect(() => assert.equal(1, 2, "something must be equal")).to.throw("something must be equal: 1 === 2");
expect(() => assert.equal(1, 2, "something must be equal")).toThrow("something must be equal: 1 === 2");
});
});

Expand Down Expand Up @@ -51,9 +50,9 @@ describe("assert", () => {
for (const {op, args, ok} of cases) {
it(`assert ${args[0]} ${op} ${args[1]} = ${ok}`, () => {
if (ok) {
expect(() => assert[op](...args)).to.not.throw();
expect(() => assert[op](...args)).not.toThrow();
} else {
expect(() => assert[op](...args)).to.throw();
expect(() => assert[op](...args)).toThrow();
}
});
}
Expand Down
7 changes: 3 additions & 4 deletions packages/utils/test/unit/base64.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import "../setup.js";
import {expect} from "chai";
import {describe, it, expect} from "vitest";
import {toBase64, fromBase64} from "../../src/index.js";

describe("toBase64", () => {
it("should encode UTF-8 string as base64 string", () => {
expect(toBase64("user:password")).to.be.equal("dXNlcjpwYXNzd29yZA==");
expect(toBase64("user:password")).toBe("dXNlcjpwYXNzd29yZA==");
});
});

describe("fromBase64", () => {
it("should decode UTF-8 string from base64 string", () => {
expect(fromBase64("dXNlcjpwYXNzd29yZA==")).to.be.equal("user:password");
expect(fromBase64("dXNlcjpwYXNzd29yZA==")).toBe("user:password");
});
});
13 changes: 6 additions & 7 deletions packages/utils/test/unit/bytes.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "../setup.js";
import {assert, expect} from "chai";
import {describe, it, expect} from "vitest";
import {intToBytes, bytesToInt, toHex, fromHex, toHexString} from "../../src/index.js";

describe("intToBytes", () => {
Expand Down Expand Up @@ -27,7 +26,7 @@ describe("intToBytes", () => {
const type = typeof input;
const length = input[1];
it(`should correctly serialize ${type} to bytes length ${length}`, () => {
assert(intToBytes(input[0], input[1]).equals(output));
expect(intToBytes(input[0], input[1])).toEqual(output);
});
}
});
Expand All @@ -43,7 +42,7 @@ describe("bytesToInt", () => {
];
for (const {input, output} of testCases) {
it(`should produce ${output}`, () => {
expect(bytesToInt(input)).to.be.equal(output);
expect(bytesToInt(input)).toBe(output);
});
}
});
Expand All @@ -57,7 +56,7 @@ describe("toHex", () => {
];
for (const {input, output} of testCases) {
it(`should convert Uint8Array to hex string ${output}`, () => {
expect(toHex(input)).to.be.equal(output);
expect(toHex(input)).toBe(output);
});
}
});
Expand All @@ -77,7 +76,7 @@ describe("fromHex", () => {

for (const {input, output} of testCases) {
it(`should convert hex string ${input} to Uint8Array`, () => {
expect(fromHex(input)).to.deep.equal(output);
expect(fromHex(input)).toEqual(output);
});
}
});
Expand All @@ -94,7 +93,7 @@ describe("toHexString", () => {

for (const {input, output} of testCases) {
it(`should convert Uint8Array to hex string ${output}`, () => {
expect(toHexString(input)).to.be.equal(output);
expect(toHexString(input)).toBe(output);
});
}
});
4 changes: 2 additions & 2 deletions packages/utils/test/unit/err.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect} from "chai";
import {describe, it, expect} from "vitest";
import {Err, isErr, mapOkResults, mapOkResultsAsync, Result} from "../../src/err.js";
import {expectDeepEquals, expectEquals} from "../utils/chai.js";

Expand Down Expand Up @@ -46,7 +46,7 @@ describe("Result Err", () => {
});

it("throw for different length", () => {
expect(() => mapOkResults([], () => [0])).to.throw();
expect(() => mapOkResults([], () => [0])).toThrow();
});

it("num to string mixed results", () => {
Expand Down
39 changes: 19 additions & 20 deletions packages/utils/test/unit/math.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "../setup.js";
import {assert} from "chai";
import {describe, it, expect} from "vitest";
import {bigIntMin, bigIntMax, intDiv, intSqrt, bigIntSqrt} from "../../src/index.js";

describe("util/maths", function () {
Expand All @@ -8,13 +7,13 @@ describe("util/maths", function () {
const a = BigInt(1);
const b = BigInt(2);
const result = bigIntMin(a, b);
assert.equal(result, a, "Should have returned a!");
expect(result).toBe(a);
});
it("if b is lt should return b", () => {
const a = BigInt(3);
const b = BigInt(2);
const result = bigIntMin(a, b);
assert.equal(result, b, "Should have returned b!");
expect(result).toBe(b);
});
});

Expand All @@ -23,78 +22,78 @@ describe("util/maths", function () {
const a = BigInt(2);
const b = BigInt(1);
const result = bigIntMax(a, b);
assert.equal(result, a, "Should have returned a!");
expect(result).toBe(a);
});
it("if b is gt should return b", () => {
const a = BigInt(2);
const b = BigInt(3);
const result = bigIntMax(a, b);
assert.equal(result, b, "Should have returned b!");
expect(result).toBe(b);
});
});

describe("intDiv", () => {
it("should divide whole number", () => {
const result = intDiv(6, 3);
assert.equal(result, 2, "Should have returned 2!");
expect(result).toBe(2);
});
it("should round less division", () => {
const result = intDiv(9, 8);
assert.equal(result, 1, "Should have returned 1!");
expect(result).toBe(1);
});
});

describe("intSqrt", () => {
it("0 should return 0", () => {
const result = intSqrt(0);
assert.equal(result, 0, "Should have returned 0!");
expect(result).toBe(0);
});
it("1 should return 1", () => {
const result = intSqrt(1);
assert.equal(result, 1, "Should have returned 1!");
expect(result).toBe(1);
});
it("3 should return 1", () => {
const result = intSqrt(3);
assert.equal(result, 1, "Should have returned 1!");
expect(result).toBe(1);
});
it("4 should return 2", () => {
const result = intSqrt(4);
assert.equal(result, 2, "Should have returned 2!");
expect(result).toBe(2);
});
it("16 should return 4", () => {
const result = intSqrt(16);
assert.equal(result, 4, "Should have returned 4!");
expect(result).toBe(4);
});
it("31 should return 5", () => {
const result = intSqrt(31);
assert.equal(result, 5, "Should have returned 5!");
expect(result).toBe(5);
});
});

describe("bigIntSqrt", () => {
it("0 should return 0", () => {
const result = bigIntSqrt(BigInt(0));
assert.equal(result.toString(), BigInt(0).toString(), "Should have returned 0!");
expect(result.toString()).toBe(BigInt(0).toString());
});
it("1 should return 1", () => {
const result = bigIntSqrt(BigInt(1));
assert.equal(result.toString(), BigInt(1).toString(), "Should have returned 1!");
expect(result.toString()).toBe(BigInt(1).toString());
});
it("3 should return 1", () => {
const result = bigIntSqrt(BigInt(3));
assert.equal(result.toString(), BigInt(1).toString(), "Should have returned 1!");
expect(result.toString()).toBe(BigInt(1).toString());
});
it("4 should return 2", () => {
const result = bigIntSqrt(BigInt(4));
assert.equal(result.toString(), BigInt(2).toString(), "Should have returned 2!");
expect(result.toString()).toBe(BigInt(2).toString());
});
it("16 should return 4", () => {
const result = bigIntSqrt(BigInt(16));
assert.equal(result.toString(), BigInt(4).toString(), "Should have returned 4!");
expect(result.toString()).toBe(BigInt(4).toString());
});
it("31 should return 5", () => {
const result = bigIntSqrt(BigInt(31));
assert.equal(result.toString(), BigInt(5).toString(), "Should have returned 5!");
expect(result.toString()).toBe(BigInt(5).toString());
});
});
});
23 changes: 11 additions & 12 deletions packages/utils/test/unit/objects.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import "../setup.js";
import {expect} from "chai";
import {describe, it, expect} from "vitest";
import {isPlainObject, objectToExpectedCase} from "../../src/index.js";

describe("Objects helper", () => {
it("should be plain object", () => {
expect(isPlainObject(Object.create({}))).to.equal(true);
expect(isPlainObject(Object.create(Object.create(Object.prototype)))).to.equal(true);
expect(isPlainObject({foo: "bar"})).to.equal(true);
expect(isPlainObject({})).to.equal(true);
expect(isPlainObject(Object.create({}))).toBe(true);
expect(isPlainObject(Object.create(Object.create(Object.prototype)))).toBe(true);
expect(isPlainObject({foo: "bar"})).toBe(true);
expect(isPlainObject({})).toBe(true);
});

it("should not be plain object", () => {
expect(isPlainObject(1)).to.equal(false);
expect(isPlainObject(["foo", "bar"])).to.equal(false);
expect(isPlainObject([])).to.equal(false);
expect(isPlainObject(null)).to.equal(false);
expect(isPlainObject(1)).toBe(false);
expect(isPlainObject(["foo", "bar"])).toBe(false);
expect(isPlainObject([])).toBe(false);
expect(isPlainObject(null)).toBe(false);
});
});

Expand Down Expand Up @@ -54,11 +53,11 @@ describe("objectToExpectedCase", () => {
for (const {id, snake, camel} of testCases) {
describe(id, () => {
it("snake > camel", () => {
expect(objectToExpectedCase(snake, "camel")).to.deep.equal(camel);
expect(objectToExpectedCase(snake, "camel")).toEqual(camel);
});

it("camel > snake", () => {
expect(objectToExpectedCase(camel, "snake")).to.deep.equal(snake);
expect(objectToExpectedCase(camel, "snake")).toEqual(snake);
});
});
}
Expand Down
35 changes: 35 additions & 0 deletions packages/utils/test/unit/promise.node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {describe, it, expect, vi, beforeEach, afterEach} from "vitest";
import {callFnWhenAwait} from "../../src/promise.js";

// TODO: Need to debug why vi.useFakeTimers() is not working for the browsers
describe("callFnWhenAwait util", function () {
beforeEach(() => {
vi.useFakeTimers();
});

afterEach(() => {
vi.clearAllTimers();
});

it("should call function while awaing for promise", async () => {
const p = new Promise<string>((resolve) => setTimeout(() => resolve("done"), 5 * 1000));
const stub = vi.fn();
const result = await Promise.all([callFnWhenAwait(p, stub, 2 * 1000), vi.advanceTimersByTimeAsync(5000)]);
expect(result[0]).toBe("done");
expect(stub).toHaveBeenCalledTimes(2);
await vi.advanceTimersByTimeAsync(5000);
expect(stub).toHaveBeenCalledTimes(2);
});

it("should throw error", async () => {
const stub = vi.fn();
const p = new Promise<string>((_, reject) => setTimeout(() => reject(new Error("done")), 5 * 1000));
try {
await Promise.all([callFnWhenAwait(p, stub, 2 * 1000), vi.advanceTimersByTimeAsync(5000)]);
expect.fail("should throw error here");
} catch (e) {
expect((e as Error).message).toBe("done");
expect(stub).toHaveBeenCalledTimes(2);
}
});
});
Loading

1 comment on commit ae04197

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for some benchmarks.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold.

Benchmark suite Current: ae04197 Previous: 2530fae Ratio
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 16.738 us/op 5.4010 us/op 3.10
Full benchmark results
Benchmark suite Current: ae04197 Previous: 2530fae Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 953.78 us/op 391.97 us/op 2.43
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 91.597 us/op 56.089 us/op 1.63
BLS verify - blst-native 1.2997 ms/op 1.1020 ms/op 1.18
BLS verifyMultipleSignatures 3 - blst-native 2.7453 ms/op 2.2812 ms/op 1.20
BLS verifyMultipleSignatures 8 - blst-native 5.9656 ms/op 5.0032 ms/op 1.19
BLS verifyMultipleSignatures 32 - blst-native 21.751 ms/op 18.692 ms/op 1.16
BLS verifyMultipleSignatures 64 - blst-native 43.014 ms/op 36.461 ms/op 1.18
BLS verifyMultipleSignatures 128 - blst-native 85.164 ms/op 75.582 ms/op 1.13
BLS deserializing 10000 signatures 908.00 ms/op 790.63 ms/op 1.15
BLS deserializing 100000 signatures 9.4173 s/op 8.0558 s/op 1.17
BLS verifyMultipleSignatures - same message - 3 - blst-native 1.3208 ms/op 1.1746 ms/op 1.12
BLS verifyMultipleSignatures - same message - 8 - blst-native 1.6567 ms/op 1.3177 ms/op 1.26
BLS verifyMultipleSignatures - same message - 32 - blst-native 2.3206 ms/op 2.1175 ms/op 1.10
BLS verifyMultipleSignatures - same message - 64 - blst-native 4.7620 ms/op 3.2463 ms/op 1.47
BLS verifyMultipleSignatures - same message - 128 - blst-native 7.9329 ms/op 6.8566 ms/op 1.16
BLS aggregatePubkeys 32 - blst-native 27.700 us/op 23.949 us/op 1.16
BLS aggregatePubkeys 128 - blst-native 100.28 us/op 85.627 us/op 1.17
getAttestationsForBlock 50.131 ms/op 39.689 ms/op 1.26
getSlashingsAndExits - default max 148.68 us/op 94.766 us/op 1.57
getSlashingsAndExits - 2k 490.05 us/op 402.02 us/op 1.22
proposeBlockBody type=full, size=empty 5.8572 ms/op 4.0703 ms/op 1.44
isKnown best case - 1 super set check 583.00 ns/op 331.00 ns/op 1.76
isKnown normal case - 2 super set checks 589.00 ns/op 321.00 ns/op 1.83
isKnown worse case - 16 super set checks 538.00 ns/op 331.00 ns/op 1.63
CheckpointStateCache - add get delete 6.2590 us/op 3.6920 us/op 1.70
validate api signedAggregateAndProof - struct 2.8553 ms/op 2.5660 ms/op 1.11
validate gossip signedAggregateAndProof - struct 2.8376 ms/op 2.5464 ms/op 1.11
validate gossip attestation - vc 640000 1.3983 ms/op 1.1868 ms/op 1.18
batch validate gossip attestation - vc 640000 - chunk 32 173.07 us/op 146.65 us/op 1.18
batch validate gossip attestation - vc 640000 - chunk 64 150.04 us/op 124.32 us/op 1.21
batch validate gossip attestation - vc 640000 - chunk 128 141.93 us/op 118.70 us/op 1.20
batch validate gossip attestation - vc 640000 - chunk 256 134.54 us/op 113.37 us/op 1.19
pickEth1Vote - no votes 1.3143 ms/op 924.25 us/op 1.42
pickEth1Vote - max votes 11.263 ms/op 13.091 ms/op 0.86
pickEth1Vote - Eth1Data hashTreeRoot value x2048 17.846 ms/op 23.765 ms/op 0.75
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 24.135 ms/op 23.761 ms/op 1.02
pickEth1Vote - Eth1Data fastSerialize value x2048 677.58 us/op 513.03 us/op 1.32
pickEth1Vote - Eth1Data fastSerialize tree x2048 6.0405 ms/op 4.4490 ms/op 1.36
bytes32 toHexString 576.00 ns/op 670.00 ns/op 0.86
bytes32 Buffer.toString(hex) 292.00 ns/op 354.00 ns/op 0.82
bytes32 Buffer.toString(hex) from Uint8Array 433.00 ns/op 520.00 ns/op 0.83
bytes32 Buffer.toString(hex) + 0x 304.00 ns/op 321.00 ns/op 0.95
Object access 1 prop 0.17200 ns/op 0.21000 ns/op 0.82
Map access 1 prop 0.14700 ns/op 0.20100 ns/op 0.73
Object get x1000 7.1480 ns/op 5.8160 ns/op 1.23
Map get x1000 0.81800 ns/op 0.73300 ns/op 1.12
Object set x1000 54.354 ns/op 28.161 ns/op 1.93
Map set x1000 39.898 ns/op 17.542 ns/op 2.27
Return object 10000 times 0.24860 ns/op 0.22640 ns/op 1.10
Throw Error 10000 times 3.9231 us/op 2.7868 us/op 1.41
fastMsgIdFn sha256 / 200 bytes 3.3660 us/op 1.9390 us/op 1.74
fastMsgIdFn h32 xxhash / 200 bytes 292.00 ns/op 299.00 ns/op 0.98
fastMsgIdFn h64 xxhash / 200 bytes 354.00 ns/op 344.00 ns/op 1.03
fastMsgIdFn sha256 / 1000 bytes 11.708 us/op 6.2100 us/op 1.89
fastMsgIdFn h32 xxhash / 1000 bytes 462.00 ns/op 405.00 ns/op 1.14
fastMsgIdFn h64 xxhash / 1000 bytes 436.00 ns/op 405.00 ns/op 1.08
fastMsgIdFn sha256 / 10000 bytes 107.03 us/op 52.287 us/op 2.05
fastMsgIdFn h32 xxhash / 10000 bytes 2.0190 us/op 1.7810 us/op 1.13
fastMsgIdFn h64 xxhash / 10000 bytes 1.4010 us/op 1.2210 us/op 1.15
send data - 1000 256B messages 21.394 ms/op 11.508 ms/op 1.86
send data - 1000 512B messages 30.547 ms/op 14.913 ms/op 2.05
send data - 1000 1024B messages 45.528 ms/op 23.158 ms/op 1.97
send data - 1000 1200B messages 42.400 ms/op 28.532 ms/op 1.49
send data - 1000 2048B messages 44.258 ms/op 36.292 ms/op 1.22
send data - 1000 4096B messages 42.705 ms/op 31.335 ms/op 1.36
send data - 1000 16384B messages 108.39 ms/op 92.439 ms/op 1.17
send data - 1000 65536B messages 452.25 ms/op 422.93 ms/op 1.07
enrSubnets - fastDeserialize 64 bits 1.4560 us/op 976.00 ns/op 1.49
enrSubnets - ssz BitVector 64 bits 536.00 ns/op 411.00 ns/op 1.30
enrSubnets - fastDeserialize 4 bits 221.00 ns/op 201.00 ns/op 1.10
enrSubnets - ssz BitVector 4 bits 519.00 ns/op 416.00 ns/op 1.25
prioritizePeers score -10:0 att 32-0.1 sync 2-0 120.23 us/op 69.770 us/op 1.72
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 151.69 us/op 77.468 us/op 1.96
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 202.28 us/op 102.49 us/op 1.97
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 337.23 us/op 179.67 us/op 1.88
prioritizePeers score 0:0 att 64-1 sync 4-1 385.72 us/op 203.80 us/op 1.89
array of 16000 items push then shift 1.6899 us/op 1.2761 us/op 1.32
LinkedList of 16000 items push then shift 9.3520 ns/op 5.9540 ns/op 1.57
array of 16000 items push then pop 122.52 ns/op 57.390 ns/op 2.13
LinkedList of 16000 items push then pop 9.3140 ns/op 5.6330 ns/op 1.65
array of 24000 items push then shift 2.5189 us/op 1.8935 us/op 1.33
LinkedList of 24000 items push then shift 9.2750 ns/op 5.7590 ns/op 1.61
array of 24000 items push then pop 158.11 ns/op 76.674 ns/op 2.06
LinkedList of 24000 items push then pop 9.2510 ns/op 5.6860 ns/op 1.63
intersect bitArray bitLen 8 6.6840 ns/op 5.0550 ns/op 1.32
intersect array and set length 8 76.439 ns/op 49.177 ns/op 1.55
intersect bitArray bitLen 128 35.304 ns/op 27.571 ns/op 1.28
intersect array and set length 128 1.0457 us/op 686.06 ns/op 1.52
bitArray.getTrueBitIndexes() bitLen 128 1.7560 us/op 1.1500 us/op 1.53
bitArray.getTrueBitIndexes() bitLen 248 3.0240 us/op 1.8300 us/op 1.65
bitArray.getTrueBitIndexes() bitLen 512 6.0470 us/op 3.4360 us/op 1.76
Buffer.concat 32 items 1.0590 us/op 838.00 ns/op 1.26
Uint8Array.set 32 items 1.9940 us/op 1.5860 us/op 1.26
Set add up to 64 items then delete first 5.0979 us/op 1.7346 us/op 2.94
OrderedSet add up to 64 items then delete first 6.2516 us/op 2.6479 us/op 2.36
Set add up to 64 items then delete last 5.3395 us/op 1.9891 us/op 2.68
OrderedSet add up to 64 items then delete last 6.5828 us/op 2.9662 us/op 2.22
Set add up to 64 items then delete middle 5.0383 us/op 1.9838 us/op 2.54
OrderedSet add up to 64 items then delete middle 8.1416 us/op 4.1603 us/op 1.96
Set add up to 128 items then delete first 10.905 us/op 3.9154 us/op 2.79
OrderedSet add up to 128 items then delete first 14.375 us/op 6.1481 us/op 2.34
Set add up to 128 items then delete last 10.301 us/op 3.7722 us/op 2.73
OrderedSet add up to 128 items then delete last 13.345 us/op 5.7034 us/op 2.34
Set add up to 128 items then delete middle 10.304 us/op 3.7910 us/op 2.72
OrderedSet add up to 128 items then delete middle 19.892 us/op 10.672 us/op 1.86
Set add up to 256 items then delete first 22.698 us/op 7.6162 us/op 2.98
OrderedSet add up to 256 items then delete first 30.380 us/op 12.176 us/op 2.50
Set add up to 256 items then delete last 21.448 us/op 7.4153 us/op 2.89
OrderedSet add up to 256 items then delete last 26.465 us/op 11.342 us/op 2.33
Set add up to 256 items then delete middle 19.921 us/op 7.3950 us/op 2.69
OrderedSet add up to 256 items then delete middle 50.123 us/op 30.140 us/op 1.66
transfer serialized Status (84 B) 1.8580 us/op 1.3580 us/op 1.37
copy serialized Status (84 B) 1.6540 us/op 1.1650 us/op 1.42
transfer serialized SignedVoluntaryExit (112 B) 2.0230 us/op 1.3710 us/op 1.48
copy serialized SignedVoluntaryExit (112 B) 1.6930 us/op 1.1720 us/op 1.44
transfer serialized ProposerSlashing (416 B) 2.7220 us/op 1.5180 us/op 1.79
copy serialized ProposerSlashing (416 B) 2.5640 us/op 1.3720 us/op 1.87
transfer serialized Attestation (485 B) 2.2170 us/op 1.5680 us/op 1.41
copy serialized Attestation (485 B) 2.3520 us/op 1.3820 us/op 1.70
transfer serialized AttesterSlashing (33232 B) 2.3480 us/op 1.6410 us/op 1.43
copy serialized AttesterSlashing (33232 B) 7.6400 us/op 3.4760 us/op 2.20
transfer serialized Small SignedBeaconBlock (128000 B) 2.8570 us/op 1.7240 us/op 1.66
copy serialized Small SignedBeaconBlock (128000 B) 21.586 us/op 8.3810 us/op 2.58
transfer serialized Avg SignedBeaconBlock (200000 B) 3.3040 us/op 1.9190 us/op 1.72
copy serialized Avg SignedBeaconBlock (200000 B) 34.673 us/op 12.711 us/op 2.73
transfer serialized BlobsSidecar (524380 B) 4.3260 us/op 2.2330 us/op 1.94
copy serialized BlobsSidecar (524380 B) 126.53 us/op 78.101 us/op 1.62
transfer serialized Big SignedBeaconBlock (1000000 B) 4.9350 us/op 2.6970 us/op 1.83
copy serialized Big SignedBeaconBlock (1000000 B) 191.64 us/op 195.67 us/op 0.98
pass gossip attestations to forkchoice per slot 3.9881 ms/op 2.7362 ms/op 1.46
forkChoice updateHead vc 100000 bc 64 eq 0 761.46 us/op 491.32 us/op 1.55
forkChoice updateHead vc 600000 bc 64 eq 0 4.5973 ms/op 2.7156 ms/op 1.69
forkChoice updateHead vc 1000000 bc 64 eq 0 7.1361 ms/op 4.4277 ms/op 1.61
forkChoice updateHead vc 600000 bc 320 eq 0 4.3850 ms/op 2.6223 ms/op 1.67
forkChoice updateHead vc 600000 bc 1200 eq 0 4.5024 ms/op 2.6921 ms/op 1.67
forkChoice updateHead vc 600000 bc 7200 eq 0 5.5094 ms/op 3.5379 ms/op 1.56
forkChoice updateHead vc 600000 bc 64 eq 1000 11.539 ms/op 10.063 ms/op 1.15
forkChoice updateHead vc 600000 bc 64 eq 10000 12.409 ms/op 9.7239 ms/op 1.28
forkChoice updateHead vc 600000 bc 64 eq 300000 18.750 ms/op 11.895 ms/op 1.58
computeDeltas 500000 validators 300 proto nodes 6.6963 ms/op 3.0617 ms/op 2.19
computeDeltas 500000 validators 1200 proto nodes 6.6349 ms/op 2.9465 ms/op 2.25
computeDeltas 500000 validators 7200 proto nodes 6.6044 ms/op 3.0148 ms/op 2.19
computeDeltas 750000 validators 300 proto nodes 10.108 ms/op 4.7349 ms/op 2.13
computeDeltas 750000 validators 1200 proto nodes 10.034 ms/op 4.7388 ms/op 2.12
computeDeltas 750000 validators 7200 proto nodes 10.212 ms/op 4.5791 ms/op 2.23
computeDeltas 1400000 validators 300 proto nodes 19.099 ms/op 9.4619 ms/op 2.02
computeDeltas 1400000 validators 1200 proto nodes 18.909 ms/op 8.9484 ms/op 2.11
computeDeltas 1400000 validators 7200 proto nodes 19.405 ms/op 9.1763 ms/op 2.11
computeDeltas 2100000 validators 300 proto nodes 28.189 ms/op 13.958 ms/op 2.02
computeDeltas 2100000 validators 1200 proto nodes 28.588 ms/op 13.560 ms/op 2.11
computeDeltas 2100000 validators 7200 proto nodes 28.890 ms/op 13.674 ms/op 2.11
computeProposerBoostScoreFromBalances 500000 validators 3.8563 ms/op 3.2580 ms/op 1.18
computeProposerBoostScoreFromBalances 750000 validators 3.7850 ms/op 3.2912 ms/op 1.15
computeProposerBoostScoreFromBalances 1400000 validators 3.8090 ms/op 3.2024 ms/op 1.19
computeProposerBoostScoreFromBalances 2100000 validators 3.9217 ms/op 3.2294 ms/op 1.21
altair processAttestation - 250000 vs - 7PWei normalcase 4.1817 ms/op 1.6979 ms/op 2.46
altair processAttestation - 250000 vs - 7PWei worstcase 4.9681 ms/op 2.8145 ms/op 1.77
altair processAttestation - setStatus - 1/6 committees join 170.41 us/op 122.77 us/op 1.39
altair processAttestation - setStatus - 1/3 committees join 323.89 us/op 210.54 us/op 1.54
altair processAttestation - setStatus - 1/2 committees join 407.52 us/op 364.88 us/op 1.12
altair processAttestation - setStatus - 2/3 committees join 518.09 us/op 404.38 us/op 1.28
altair processAttestation - setStatus - 4/5 committees join 695.28 us/op 691.76 us/op 1.01
altair processAttestation - setStatus - 100% committees join 829.15 us/op 647.73 us/op 1.28
altair processBlock - 250000 vs - 7PWei normalcase 11.080 ms/op 12.047 ms/op 0.92
altair processBlock - 250000 vs - 7PWei normalcase hashState 37.066 ms/op 40.059 ms/op 0.93
altair processBlock - 250000 vs - 7PWei worstcase 39.681 ms/op 49.499 ms/op 0.80
altair processBlock - 250000 vs - 7PWei worstcase hashState 98.092 ms/op 136.43 ms/op 0.72
phase0 processBlock - 250000 vs - 7PWei normalcase 3.3532 ms/op 4.0689 ms/op 0.82
phase0 processBlock - 250000 vs - 7PWei worstcase 34.221 ms/op 34.489 ms/op 0.99
altair processEth1Data - 250000 vs - 7PWei normalcase 629.60 us/op 750.49 us/op 0.84
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 16.738 us/op 5.4010 us/op 3.10
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 72.708 us/op 52.845 us/op 1.38
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 28.588 us/op 14.676 us/op 1.95
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 17.107 us/op 9.1200 us/op 1.88
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 205.68 us/op 154.45 us/op 1.33
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.3440 ms/op 1.5432 ms/op 0.87
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 1.7247 ms/op 1.0401 ms/op 1.66
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 2.2533 ms/op 1.4502 ms/op 1.55
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 5.1911 ms/op 2.2438 ms/op 2.31
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 2.7444 ms/op 1.7352 ms/op 1.58
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 6.2958 ms/op 3.3702 ms/op 1.87
Tree 40 250000 create 428.75 ms/op 272.28 ms/op 1.57
Tree 40 250000 get(125000) 219.17 ns/op 105.15 ns/op 2.08
Tree 40 250000 set(125000) 1.1600 us/op 732.16 ns/op 1.58
Tree 40 250000 toArray() 24.457 ms/op 14.880 ms/op 1.64
Tree 40 250000 iterate all - toArray() + loop 23.830 ms/op 14.651 ms/op 1.63
Tree 40 250000 iterate all - get(i) 79.849 ms/op 40.548 ms/op 1.97
MutableVector 250000 create 14.134 ms/op 11.686 ms/op 1.21
MutableVector 250000 get(125000) 6.9630 ns/op 5.3550 ns/op 1.30
MutableVector 250000 set(125000) 416.01 ns/op 196.76 ns/op 2.11
MutableVector 250000 toArray() 4.2759 ms/op 2.5651 ms/op 1.67
MutableVector 250000 iterate all - toArray() + loop 4.7276 ms/op 2.7324 ms/op 1.73
MutableVector 250000 iterate all - get(i) 1.5378 ms/op 1.3298 ms/op 1.16
Array 250000 create 3.4074 ms/op 2.3689 ms/op 1.44
Array 250000 clone - spread 1.2366 ms/op 9.1842 ms/op 0.13
Array 250000 get(125000) 1.0770 ns/op 1.0410 ns/op 1.03
Array 250000 set(125000) 4.2940 ns/op 1.1490 ns/op 3.74
Array 250000 iterate all - loop 169.12 us/op 147.23 us/op 1.15
effectiveBalanceIncrements clone Uint8Array 300000 30.017 us/op 18.699 us/op 1.61
effectiveBalanceIncrements clone MutableVector 300000 368.00 ns/op 352.00 ns/op 1.05
effectiveBalanceIncrements rw all Uint8Array 300000 205.73 us/op 176.45 us/op 1.17
effectiveBalanceIncrements rw all MutableVector 300000 89.885 ms/op 61.459 ms/op 1.46
phase0 afterProcessEpoch - 250000 vs - 7PWei 117.99 ms/op 77.303 ms/op 1.53
phase0 beforeProcessEpoch - 250000 vs - 7PWei 54.934 ms/op 44.584 ms/op 1.23
altair processEpoch - mainnet_e81889 599.21 ms/op 428.32 ms/op 1.40
mainnet_e81889 - altair beforeProcessEpoch 104.05 ms/op 74.221 ms/op 1.40
mainnet_e81889 - altair processJustificationAndFinalization 31.877 us/op 10.411 us/op 3.06
mainnet_e81889 - altair processInactivityUpdates 9.1759 ms/op 5.9123 ms/op 1.55
mainnet_e81889 - altair processRewardsAndPenalties 78.292 ms/op 58.935 ms/op 1.33
mainnet_e81889 - altair processRegistryUpdates 4.0760 us/op 2.5700 us/op 1.59
mainnet_e81889 - altair processSlashings 614.00 ns/op 601.00 ns/op 1.02
mainnet_e81889 - altair processEth1DataReset 1.1010 us/op 571.00 ns/op 1.93
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.6488 ms/op 1.7600 ms/op 0.94
mainnet_e81889 - altair processSlashingsReset 7.4440 us/op 2.4930 us/op 2.99
mainnet_e81889 - altair processRandaoMixesReset 10.319 us/op 2.8330 us/op 3.64
mainnet_e81889 - altair processHistoricalRootsUpdate 1.1270 us/op 649.00 ns/op 1.74
mainnet_e81889 - altair processParticipationFlagUpdates 3.8430 us/op 1.4530 us/op 2.64
mainnet_e81889 - altair processSyncCommitteeUpdates 1.8180 us/op 532.00 ns/op 3.42
mainnet_e81889 - altair afterProcessEpoch 134.34 ms/op 80.565 ms/op 1.67
capella processEpoch - mainnet_e217614 2.1035 s/op 2.2132 s/op 0.95
mainnet_e217614 - capella beforeProcessEpoch 521.11 ms/op 429.03 ms/op 1.21
mainnet_e217614 - capella processJustificationAndFinalization 19.946 us/op 11.791 us/op 1.69
mainnet_e217614 - capella processInactivityUpdates 18.541 ms/op 19.446 ms/op 0.95
mainnet_e217614 - capella processRewardsAndPenalties 419.00 ms/op 383.38 ms/op 1.09
mainnet_e217614 - capella processRegistryUpdates 23.229 us/op 13.682 us/op 1.70
mainnet_e217614 - capella processSlashings 381.00 ns/op 591.00 ns/op 0.64
mainnet_e217614 - capella processEth1DataReset 388.00 ns/op 628.00 ns/op 0.62
mainnet_e217614 - capella processEffectiveBalanceUpdates 4.4556 ms/op 3.4986 ms/op 1.27
mainnet_e217614 - capella processSlashingsReset 3.9460 us/op 3.0990 us/op 1.27
mainnet_e217614 - capella processRandaoMixesReset 4.5070 us/op 8.2410 us/op 0.55
mainnet_e217614 - capella processHistoricalRootsUpdate 446.00 ns/op 793.00 ns/op 0.56
mainnet_e217614 - capella processParticipationFlagUpdates 1.4930 us/op 1.3540 us/op 1.10
mainnet_e217614 - capella afterProcessEpoch 303.14 ms/op 227.97 ms/op 1.33
phase0 processEpoch - mainnet_e58758 457.45 ms/op 415.10 ms/op 1.10
mainnet_e58758 - phase0 beforeProcessEpoch 123.36 ms/op 142.03 ms/op 0.87
mainnet_e58758 - phase0 processJustificationAndFinalization 18.357 us/op 16.703 us/op 1.10
mainnet_e58758 - phase0 processRewardsAndPenalties 54.946 ms/op 47.537 ms/op 1.16
mainnet_e58758 - phase0 processRegistryUpdates 10.032 us/op 9.0180 us/op 1.11
mainnet_e58758 - phase0 processSlashings 748.00 ns/op 978.00 ns/op 0.76
mainnet_e58758 - phase0 processEth1DataReset 427.00 ns/op 640.00 ns/op 0.67
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.2213 ms/op 969.53 us/op 1.26
mainnet_e58758 - phase0 processSlashingsReset 3.5860 us/op 4.1260 us/op 0.87
mainnet_e58758 - phase0 processRandaoMixesReset 7.1400 us/op 4.2310 us/op 1.69
mainnet_e58758 - phase0 processHistoricalRootsUpdate 728.00 ns/op 997.00 ns/op 0.73
mainnet_e58758 - phase0 processParticipationRecordUpdates 8.0230 us/op 5.0010 us/op 1.60
mainnet_e58758 - phase0 afterProcessEpoch 104.83 ms/op 68.392 ms/op 1.53
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.4303 ms/op 1.2471 ms/op 1.15
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.5756 ms/op 1.2880 ms/op 1.22
altair processInactivityUpdates - 250000 normalcase 40.451 ms/op 30.384 ms/op 1.33
altair processInactivityUpdates - 250000 worstcase 41.174 ms/op 26.847 ms/op 1.53
phase0 processRegistryUpdates - 250000 normalcase 9.6230 us/op 11.336 us/op 0.85
phase0 processRegistryUpdates - 250000 badcase_full_deposits 414.46 us/op 391.91 us/op 1.06
phase0 processRegistryUpdates - 250000 worstcase 0.5 163.35 ms/op 114.00 ms/op 1.43
altair processRewardsAndPenalties - 250000 normalcase 60.280 ms/op 41.015 ms/op 1.47
altair processRewardsAndPenalties - 250000 worstcase 58.766 ms/op 54.871 ms/op 1.07
phase0 getAttestationDeltas - 250000 normalcase 12.757 ms/op 5.9943 ms/op 2.13
phase0 getAttestationDeltas - 250000 worstcase 11.244 ms/op 8.3034 ms/op 1.35
phase0 processSlashings - 250000 worstcase 105.65 us/op 84.615 us/op 1.25
altair processSyncCommitteeUpdates - 250000 166.87 ms/op 127.03 ms/op 1.31
BeaconState.hashTreeRoot - No change 260.00 ns/op 447.00 ns/op 0.58
BeaconState.hashTreeRoot - 1 full validator 148.03 us/op 130.44 us/op 1.13
BeaconState.hashTreeRoot - 32 full validator 1.5588 ms/op 1.4590 ms/op 1.07
BeaconState.hashTreeRoot - 512 full validator 16.166 ms/op 18.472 ms/op 0.88
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 200.81 us/op 150.25 us/op 1.34
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 2.6187 ms/op 2.0279 ms/op 1.29
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 37.153 ms/op 32.852 ms/op 1.13
BeaconState.hashTreeRoot - 1 balances 195.12 us/op 118.80 us/op 1.64
BeaconState.hashTreeRoot - 32 balances 1.3897 ms/op 1.1455 ms/op 1.21
BeaconState.hashTreeRoot - 512 balances 14.240 ms/op 10.696 ms/op 1.33
BeaconState.hashTreeRoot - 250000 balances 225.44 ms/op 192.93 ms/op 1.17
aggregationBits - 2048 els - zipIndexesInBitList 21.629 us/op 10.749 us/op 2.01
byteArrayEquals 32 77.117 ns/op 65.390 ns/op 1.18
Buffer.compare 32 56.013 ns/op 39.177 ns/op 1.43
byteArrayEquals 1024 2.1048 us/op 1.7661 us/op 1.19
Buffer.compare 1024 72.692 ns/op 47.677 ns/op 1.52
byteArrayEquals 16384 33.789 us/op 28.330 us/op 1.19
Buffer.compare 16384 279.05 ns/op 223.57 ns/op 1.25
byteArrayEquals 123687377 261.05 ms/op 206.09 ms/op 1.27
Buffer.compare 123687377 8.3848 ms/op 7.7511 ms/op 1.08
byteArrayEquals 32 - diff last byte 73.887 ns/op 65.340 ns/op 1.13
Buffer.compare 32 - diff last byte 57.691 ns/op 42.034 ns/op 1.37
byteArrayEquals 1024 - diff last byte 2.0969 us/op 1.9043 us/op 1.10
Buffer.compare 1024 - diff last byte 74.086 ns/op 48.633 ns/op 1.52
byteArrayEquals 16384 - diff last byte 34.738 us/op 27.886 us/op 1.25
Buffer.compare 16384 - diff last byte 261.81 ns/op 241.23 ns/op 1.09
byteArrayEquals 123687377 - diff last byte 255.27 ms/op 213.52 ms/op 1.20
Buffer.compare 123687377 - diff last byte 9.2030 ms/op 6.4727 ms/op 1.42
byteArrayEquals 32 - random bytes 6.3060 ns/op 5.3600 ns/op 1.18
Buffer.compare 32 - random bytes 63.482 ns/op 39.720 ns/op 1.60
byteArrayEquals 1024 - random bytes 6.5000 ns/op 5.0070 ns/op 1.30
Buffer.compare 1024 - random bytes 62.762 ns/op 37.014 ns/op 1.70
byteArrayEquals 16384 - random bytes 6.4210 ns/op 4.9680 ns/op 1.29
Buffer.compare 16384 - random bytes 62.858 ns/op 36.888 ns/op 1.70
byteArrayEquals 123687377 - random bytes 10.210 ns/op 8.1300 ns/op 1.26
Buffer.compare 123687377 - random bytes 79.230 ns/op 39.220 ns/op 2.02
regular array get 100000 times 47.110 us/op 41.615 us/op 1.13
wrappedArray get 100000 times 47.812 us/op 41.354 us/op 1.16
arrayWithProxy get 100000 times 15.260 ms/op 9.2633 ms/op 1.65
ssz.Root.equals 56.399 ns/op 55.729 ns/op 1.01
byteArrayEquals 55.829 ns/op 53.145 ns/op 1.05
Buffer.compare 12.687 ns/op 9.8420 ns/op 1.29
shuffle list - 16384 els 7.3500 ms/op 4.7429 ms/op 1.55
shuffle list - 250000 els 107.83 ms/op 71.127 ms/op 1.52
processSlot - 1 slots 21.981 us/op 15.393 us/op 1.43
processSlot - 32 slots 3.3328 ms/op 2.8292 ms/op 1.18
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 64.960 ms/op 52.256 ms/op 1.24
getCommitteeAssignments - req 1 vs - 250000 vc 2.6125 ms/op 2.2709 ms/op 1.15
getCommitteeAssignments - req 100 vs - 250000 vc 3.8073 ms/op 3.2926 ms/op 1.16
getCommitteeAssignments - req 1000 vs - 250000 vc 4.4156 ms/op 3.7173 ms/op 1.19
findModifiedValidators - 10000 modified validators 586.48 ms/op 433.44 ms/op 1.35
findModifiedValidators - 1000 modified validators 467.95 ms/op 334.49 ms/op 1.40
findModifiedValidators - 100 modified validators 476.66 ms/op 298.28 ms/op 1.60
findModifiedValidators - 10 modified validators 508.90 ms/op 343.26 ms/op 1.48
findModifiedValidators - 1 modified validators 522.84 ms/op 300.73 ms/op 1.74
findModifiedValidators - no difference 487.33 ms/op 286.71 ms/op 1.70
compare ViewDUs 5.8447 s/op 3.9242 s/op 1.49
compare each validator Uint8Array 2.0722 s/op 1.9307 s/op 1.07
compare ViewDU to Uint8Array 1.6021 s/op 786.47 ms/op 2.04
migrate state 1000000 validators, 24 modified, 0 new 985.67 ms/op 748.66 ms/op 1.32
migrate state 1000000 validators, 1700 modified, 1000 new 1.3153 s/op 941.61 ms/op 1.40
migrate state 1000000 validators, 3400 modified, 2000 new 1.3877 s/op 1.1895 s/op 1.17
migrate state 1500000 validators, 24 modified, 0 new 886.91 ms/op 711.67 ms/op 1.25
migrate state 1500000 validators, 1700 modified, 1000 new 1.0962 s/op 931.91 ms/op 1.18
migrate state 1500000 validators, 3400 modified, 2000 new 1.2900 s/op 1.0465 s/op 1.23
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.4600 ns/op 4.3100 ns/op 1.03
state getBlockRootAtSlot - 250000 vs - 7PWei 549.45 ns/op 405.66 ns/op 1.35
computeProposers - vc 250000 9.2410 ms/op 6.1354 ms/op 1.51
computeEpochShuffling - vc 250000 106.76 ms/op 70.765 ms/op 1.51
getNextSyncCommittee - vc 250000 156.19 ms/op 113.51 ms/op 1.38
computeSigningRoot for AttestationData 25.443 us/op 26.077 us/op 0.98
hash AttestationData serialized data then Buffer.toString(base64) 2.3337 us/op 1.2731 us/op 1.83
toHexString serialized data 1.0939 us/op 794.82 ns/op 1.38
Buffer.toString(base64) 222.23 ns/op 152.03 ns/op 1.46

Please sign in to comment.