summaryrefslogtreecommitdiffstats
path: root/BENCHMARK_SUMMARY.md
diff options
context:
space:
mode:
Diffstat (limited to 'BENCHMARK_SUMMARY.md')
-rw-r--r--BENCHMARK_SUMMARY.md154
1 files changed, 154 insertions, 0 deletions
diff --git a/BENCHMARK_SUMMARY.md b/BENCHMARK_SUMMARY.md
new file mode 100644
index 0000000..e7f5b6d
--- /dev/null
+++ b/BENCHMARK_SUMMARY.md
@@ -0,0 +1,154 @@
1# Benchmark Results Summary
2
3Comparison of three Go Nostr libraries: **NWIO** (northwest.io/nostr), **NBD** (github.com/nbd-wtf/go-nostr), and **Fiat** (fiatjaf.com/nostr)
4
5## Quick Performance Overview
6
7### 🏆 Winners by Category
8
9| Operation | Winner | Performance |
10|-----------|--------|-------------|
11| **Event Unmarshal** | NWIO/Fiat | ~2.5 µs (tied) |
12| **Event Marshal** | NWIO | 1.79 µs (fastest, least memory) |
13| **Event Serialize** | NBD | 129 ns (3x faster than NWIO) |
14| **Compute ID** | Fiat | 276 ns (2x faster than NWIO) |
15| **Generate Key** | NBD | 470 ns (80x faster!) |
16| **Event Sign** | NBD/Fiat | ~59 µs (2x faster than NWIO) |
17| **Event Verify** | NWIO | 99.7 µs (slightly faster) |
18| **Filter Match** | NWIO | 7.1 ns (2x faster than Fiat) |
19| **Filter Complex** | NWIO | 30.9 ns (fastest) |
20
21## Detailed Results
22
23### Event Unmarshaling (JSON → Event)
24```
25NWIO: 2,541 ns/op 888 B/op 17 allocs/op ⭐ FASTEST, LOW MEMORY
26NBD: 2,832 ns/op 944 B/op 13 allocs/op
27Fiat: 2,545 ns/op 752 B/op 10 allocs/op ⭐ LEAST MEMORY
28```
29**Analysis**: All three are very competitive. NWIO and Fiat are effectively tied. Fiat uses least memory.
30
31### Event Marshaling (Event → JSON)
32```
33NWIO: 1,790 ns/op 1,010 B/op 3 allocs/op ⭐ FASTEST, LEAST ALLOCS
34NBD: 1,819 ns/op 1,500 B/op 6 allocs/op
35Fiat: 1,971 ns/op 2,254 B/op 13 allocs/op
36```
37**Analysis**: NWIO is fastest with minimal allocations. Significant memory advantage over competitors.
38
39### Event Serialization (for ID computation)
40```
41NWIO: 391 ns/op 360 B/op 7 allocs/op
42NBD: 129 ns/op 208 B/op 2 allocs/op ⭐ FASTEST, 3x faster
43Fiat: 161 ns/op 400 B/op 3 allocs/op
44```
45**Analysis**: NBD dominates here with optimized serialization. NWIO has room for improvement.
46
47### Event ID Computation
48```
49NWIO: 608 ns/op 488 B/op 9 allocs/op
50NBD: 302 ns/op 336 B/op 4 allocs/op
51Fiat: 276 ns/op 400 B/op 3 allocs/op ⭐ FASTEST
52```
53**Analysis**: NBD and Fiat are 2x faster. NWIO should optimize ID computation path.
54
55### Key Generation
56```
57NWIO: 37,689 ns/op 208 B/op 4 allocs/op
58NBD: 470 ns/op 369 B/op 8 allocs/op ⭐ FASTEST, 80x faster!
59Fiat: 25,375 ns/op 272 B/op 5 allocs/op
60```
61**Analysis**: ⚠️ NWIO is significantly slower. NBD appears to use a different key generation strategy. This is the biggest performance gap.
62
63### Event Signing
64```
65NWIO: 129,854 ns/op 2,363 B/op 42 allocs/op
66NBD: 59,069 ns/op 2,112 B/op 35 allocs/op ⭐ TIED FASTEST
67Fiat: 58,572 ns/op 1,760 B/op 29 allocs/op ⭐ LEAST MEMORY
68```
69**Analysis**: NBD and Fiat are 2x faster. NWIO has more allocations in signing path.
70
71### Event Verification
72```
73NWIO: 99,744 ns/op 953 B/op 19 allocs/op ⭐ FASTEST
74NBD: 105,995 ns/op 624 B/op 11 allocs/op ⭐ LEAST MEMORY
75Fiat: 103,744 ns/op 640 B/op 9 allocs/op
76```
77**Analysis**: NWIO is slightly faster (6% faster than others). Very competitive across all three.
78
79### Filter Matching (Simple)
80```
81NWIO: 7.1 ns/op 0 B/op 0 allocs/op ⭐ FASTEST, 2x faster
82NBD: 10.8 ns/op 0 B/op 0 allocs/op
83Fiat: 16.4 ns/op 0 B/op 0 allocs/op
84```
85**Analysis**: NWIO excels at filter matching! Zero allocations across all libraries.
86
87### Filter Matching (Complex with Tags)
88```
89NWIO: 30.9 ns/op 0 B/op 0 allocs/op ⭐ FASTEST
90NBD: 33.4 ns/op 0 B/op 0 allocs/op
91Fiat: 42.6 ns/op 0 B/op 0 allocs/op
92```
93**Analysis**: NWIO maintains lead in complex filters. Important for relay implementations.
94
95## Optimization Opportunities for NWIO
96
97### High Priority 🔴
981. **Key Generation** - 80x slower than NBD
99 - Current: 37.7 µs
100 - Target: ~500 ns (similar to NBD)
101 - Impact: Critical for client applications
102
1032. **Event Signing** - 2x slower than competitors
104 - Current: 130 µs
105 - Target: ~60 µs (match NBD/Fiat)
106 - Impact: High for client applications
107
108### Medium Priority 🟡
1093. **Event Serialization** - 3x slower than NBD
110 - Current: 391 ns
111 - Target: ~130 ns (match NBD)
112 - Impact: Used in ID computation
113
1144. **ID Computation** - 2x slower than competitors
115 - Current: 608 ns
116 - Target: ~280 ns (match Fiat)
117 - Impact: Affects every event processing
118
119## Current Strengths of NWIO ✅
120
1211. **Filter Matching** - 2x faster than Fiat, fastest overall
1222. **Event Marshaling** - Fastest with minimal allocations
1233. **Event Verification** - Slightly faster than competitors
1244. **Memory Efficiency** - Competitive or better in most operations
125
126## Recommendations
127
128### For Relay Implementations
129- **NWIO excels**: Best filter matching performance
130- All three are competitive for event parsing/verification
131
132### For Client Implementations
133- **NBD/Fiat preferred**: Much faster key generation and signing
134- NWIO needs optimization in crypto operations
135
136### Overall Assessment
137- **NWIO**: Best for relay/filter-heavy workloads
138- **NBD**: Most balanced, excellent crypto performance
139- **Fiat**: Good all-around, lowest memory in some operations
140
141## Running Your Own Benchmarks
142
143```bash
144# Run all benchmarks
145./run_benchmarks.sh
146
147# Compare specific operations
148go test -bench=BenchmarkEventSign -benchmem comparison_bench_test.go
149go test -bench=BenchmarkFilterMatch -benchmem comparison_bench_test.go
150
151# Statistical analysis with benchstat
152go test -bench=. -count=10 comparison_bench_test.go > results.txt
153benchstat results.txt
154```