summaryrefslogtreecommitdiffstats
path: root/BENCHMARKS.md
diff options
context:
space:
mode:
authorClawd <ai@clawd.bot>2026-02-16 12:12:37 -0800
committerClawd <ai@clawd.bot>2026-02-16 12:12:37 -0800
commit9d20d2281f4698024b7be67d1b86178b4e8e2484 (patch)
treef72986f33904afc36b72dd8bbb7d83802fee0479 /BENCHMARKS.md
parent4b7dfe1e7764d8424b1be935c7fea09a102382e8 (diff)
Clean up project structure
- Add README.md - Move benchmark files to benchmarks/ - Move PLAN.md to .claude/ - Add .gitignore
Diffstat (limited to 'BENCHMARKS.md')
-rw-r--r--BENCHMARKS.md130
1 files changed, 0 insertions, 130 deletions
diff --git a/BENCHMARKS.md b/BENCHMARKS.md
deleted file mode 100644
index 1a671c1..0000000
--- a/BENCHMARKS.md
+++ /dev/null
@@ -1,130 +0,0 @@
1# Nostr Library Benchmarks
2
3This directory contains comprehensive benchmarks comparing three popular Go Nostr libraries:
4
5- **NWIO** (`code.northwest.io/nostr`) - This library
6- **NBD** (`github.com/nbd-wtf/go-nostr`) - Popular community library
7- **Fiat** (`fiatjaf.com/nostr`) - Original implementation by Fiatjaf
8
9## Benchmark Categories
10
11### Event Operations
12- **Unmarshal**: Parsing JSON into Event struct
13- **Marshal**: Serializing Event struct to JSON
14- **Serialize**: Canonical serialization for ID computation
15- **ComputeID**: Computing event ID hash
16- **Sign**: Signing events with private key
17- **Verify**: Verifying event signatures
18
19### Key Operations
20- **GenerateKey**: Generating new private keys
21
22### Filter Operations
23- **FilterMatch**: Simple filter matching (kind, author)
24- **FilterMatchComplex**: Complex filter matching (with tags, prefix matching)
25
26## Running Benchmarks
27
28**Important**: The comparison benchmarks are in a separate module (`benchmarks/comparison/`) to avoid polluting the main module dependencies with competitor libraries.
29
30### Quick Start
31
32Run all comparison benchmarks:
33```bash
34cd benchmarks/comparison
35go test -bench=. -benchmem -benchtime=1s
36```
37
38### Specific Benchmark Groups
39
40Event unmarshaling:
41```bash
42cd benchmarks/comparison
43go test -bench=BenchmarkEventUnmarshal -benchmem
44```
45
46Event signing:
47```bash
48cd benchmarks/comparison
49go test -bench=BenchmarkEventSign -benchmem
50```
51
52Event verification:
53```bash
54cd benchmarks/comparison
55go test -bench=BenchmarkEventVerify -benchmem
56```
57
58Filter matching:
59```bash
60cd benchmarks/comparison
61go test -bench=BenchmarkFilterMatch -benchmem
62```
63
64### Compare Single Library
65
66NWIO only:
67```bash
68cd benchmarks/comparison
69go test -bench='.*_NWIO' -benchmem
70```
71
72NBD only:
73```bash
74cd benchmarks/comparison
75go test -bench='.*_NBD' -benchmem
76```
77
78Fiat only:
79```bash
80cd benchmarks/comparison
81go test -bench='.*_Fiat' -benchmem
82```
83
84## Analyzing Results
85
86Use `benchstat` for statistical analysis:
87
88```bash
89# Install benchstat
90go install golang.org/x/perf/cmd/benchstat@latest
91
92# Run benchmarks multiple times and compare
93cd benchmarks/comparison
94go test -bench=. -benchmem -count=10 > results.txt
95benchstat results.txt
96```
97
98Compare two specific libraries:
99```bash
100cd benchmarks/comparison
101go test -bench='.*_NWIO' -benchmem -count=10 > nwio.txt
102go test -bench='.*_NBD' -benchmem -count=10 > nbd.txt
103benchstat nwio.txt nbd.txt
104```
105
106## Understanding the Output
107
108Example output:
109```
110BenchmarkEventSign_NWIO-24 50000 35421 ns/op 1024 B/op 12 allocs/op
111```
112
113- `50000`: Number of iterations
114- `35421 ns/op`: Nanoseconds per operation (lower is better)
115- `1024 B/op`: Bytes allocated per operation (lower is better)
116- `12 allocs/op`: Memory allocations per operation (lower is better)
117
118## Performance Tips
119
1201. **Event Unmarshaling**: Critical for relay implementations
1212. **Event Signing**: Important for client implementations
1223. **Event Verification**: Critical for all implementations
1234. **Filter Matching**: Important for relay implementations with many subscriptions
124
125## Notes
126
127- All benchmarks use realistic event data
128- Benchmarks run with default Go test timeout
129- Results may vary based on hardware and system load
130- Use `-benchtime=5s` for more stable results on noisy systems