Skip to content

Commit efd1c31

Browse files
committed
Add more benchmarks
1 parent 3b912c7 commit efd1c31

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"dist"
3333
],
3434
"scripts": {
35+
"benchmark": "vitest bench",
3536
"build": "ts-bridge --project tsconfig.build.json --clean",
3637
"build:docs": "typedoc",
3738
"generate-vectors": "ts-node scripts/generate-vectors.ts > ./test/vectors/derivation.json",

src/SLIP10Node.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ describe('SLIP10Node', () => {
11221122

11231123
const { publicKey, ...json } = baseNode.toJSON();
11241124

1125-
const spy = jest.spyOn(secp256k1, 'getPublicKey');
1125+
const spy = vi.spyOn(secp256k1, 'getPublicKey');
11261126

11271127
const node = await SLIP10Node.fromExtendedKey(json);
11281128
expect(spy).not.toHaveBeenCalled();

test/key-tree.bench.ts

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,75 @@
11
import { describe, bench } from 'vitest';
22

33
import fixtures from './fixtures';
4-
import { secp256k1, SLIP10Node } from '../src';
4+
import { secp256k1, ed25519, ed25519Bip32, SLIP10Node } from '../src';
55
import { deriveChildKey } from '../src/derivers/bip39';
66

7-
describe('SLIP10Node', async () => {
8-
const privateNode = await deriveChildKey({
9-
path: fixtures.local.seed,
10-
curve: secp256k1,
11-
});
7+
describe('SLIP10Node', () => {
8+
describe('fromExtendedKey', () => {
9+
describe('secp256k1', async () => {
10+
const privateNode = await deriveChildKey({
11+
path: fixtures.local.seed,
12+
curve: secp256k1,
13+
});
1214

13-
const publicNode = privateNode.neuter();
15+
const publicNode = privateNode.neuter();
1416

15-
describe('fromExtendedKey', () => {
16-
describe('from a JSON object', () => {
17-
bench('with a private key', async () => {
18-
await SLIP10Node.fromExtendedKey(privateNode.toJSON());
17+
describe('from a JSON object', () => {
18+
bench('with a private key', async () => {
19+
await SLIP10Node.fromExtendedKey(privateNode.toJSON());
20+
});
21+
22+
bench('with a public key', async () => {
23+
await SLIP10Node.fromExtendedKey(publicNode.toJSON());
24+
});
1925
});
2026

21-
bench('with a public key', async () => {
22-
await SLIP10Node.fromExtendedKey(publicNode.toJSON());
27+
describe('from an extended key', () => {
28+
bench('with a private key', async () => {
29+
await SLIP10Node.fromExtendedKey(privateNode.extendedKey);
30+
});
31+
32+
bench('with a public key', async () => {
33+
await SLIP10Node.fromExtendedKey(publicNode.extendedKey);
34+
});
2335
});
2436
});
2537

26-
describe('from an extended key', () => {
27-
bench('with a private key', async () => {
28-
await SLIP10Node.fromExtendedKey(privateNode.extendedKey);
38+
describe('ed25519', async () => {
39+
const privateNode = await deriveChildKey({
40+
path: fixtures.local.seed,
41+
curve: ed25519,
2942
});
3043

31-
bench('with a public key', async () => {
32-
await SLIP10Node.fromExtendedKey(publicNode.extendedKey);
44+
const publicNode = privateNode.neuter();
45+
46+
describe('from a JSON object', () => {
47+
bench('with a private key', async () => {
48+
await SLIP10Node.fromExtendedKey(privateNode.toJSON());
49+
});
50+
51+
bench('with a public key', async () => {
52+
await SLIP10Node.fromExtendedKey(publicNode.toJSON());
53+
});
54+
});
55+
});
56+
57+
describe('ed25519Bip32', async () => {
58+
const privateNode = await deriveChildKey({
59+
path: fixtures.local.seed,
60+
curve: ed25519Bip32,
61+
});
62+
63+
const publicNode = privateNode.neuter();
64+
65+
describe('from a JSON object', () => {
66+
bench('with a private key', async () => {
67+
await SLIP10Node.fromExtendedKey(privateNode.toJSON());
68+
});
69+
70+
bench('with a public key', async () => {
71+
await SLIP10Node.fromExtendedKey(publicNode.toJSON());
72+
});
3373
});
3474
});
3575
});

0 commit comments

Comments
 (0)