Skip to content

Commit 31857a7

Browse files
committed
docs: add benchmark & profiling book chapters
1 parent e423f25 commit 31857a7

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Benchmark
2+
3+
We take two approaches to benchmarking EDR:
4+
5+
1. Automated benchmarks using `criterion`
6+
2. Manual benchmarks using repositories of dependants
7+
8+
## Automated
9+
10+
## Manual
11+
12+
To measure real-world performance, we use a build of [Hardhat](https://github.com/NomicFoundation/hardhat) with EDR in third-party projects.
13+
To make a local build of Hardhat available for linking in other packages, run:
14+
15+
```bash
16+
cd packages/hardhat-core &&
17+
pnpm build &&
18+
npm link
19+
```
20+
21+
For this example we will use [openzeppelin-contracts](https://github.com/OpenZeppelin/openzeppelin-contracts):
22+
23+
```bash
24+
git clone https://github.com/OpenZeppelin/openzeppelin-contracts.git &&
25+
cd openzeppelin-contracts &&
26+
npm install
27+
```
28+
29+
To use your local hardhat build in a third-party project, run:
30+
31+
```bash
32+
npm link hardhat
33+
```
34+
35+
To validate that this worked, you can run:
36+
37+
```bash
38+
file node_modules/hardhat
39+
```
40+
41+
The expected output will look similar to this:
42+
43+
```bash
44+
node_modules/hardhat: symbolic link to ../../hardhat/packages/hardhat-core
45+
```
46+
47+
To prevent the benchmark from being tainted by smart contract compilation, we first run:
48+
49+
```bash
50+
npx hardhat compile
51+
```
52+
53+
Finally, to benchmark the third-party project, we time its test suite.
54+
For example:
55+
56+
```bash
57+
time npx hardhat test
58+
```
59+
60+
Resulting in output similar to:
61+
62+
```bash
63+
npx hardhat test 68.99s user 9.59s system 130% cpu 1:00.40 total
64+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Profiling
2+
3+
```bash
4+
yarn build:tracing
5+
```
6+
7+
When you now run `edr`, it will generate a `tracing.folded` file in the current working directory.
8+
Once the profiling run has completed, we can use [`inferno`](https://docs.rs/tracing-flame/latest/tracing_flame/#generating-the-image) to generate flamegraphs from the collected data.
9+
To install `inferno`, run:
10+
11+
```bash
12+
cargo install inferno
13+
```
14+
15+
When we want to analyze the run with its exact order preserved, run:
16+
17+
```bash
18+
cat tracing.folded | inferno-flamegraph --flamechart > tracing-flamechart.svg
19+
```
20+
21+
22+
Alternatively, when we don't care about those details, a flamegraph with identical stack frames collapsed can be generated by running:
23+
24+
```bash
25+
cat tracing.folded | inferno-flamegraph > tracing-flamegraph.svg
26+
```

0 commit comments

Comments
 (0)