diff options
| author | Clawd <ai@clawd.bot> | 2026-02-16 12:12:37 -0800 |
|---|---|---|
| committer | Clawd <ai@clawd.bot> | 2026-02-16 12:12:37 -0800 |
| commit | 9d20d2281f4698024b7be67d1b86178b4e8e2484 (patch) | |
| tree | f72986f33904afc36b72dd8bbb7d83802fee0479 /BENCHMARKS.md | |
| parent | 4b7dfe1e7764d8424b1be935c7fea09a102382e8 (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.md | 130 |
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 | |||
| 3 | This 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 | |||
| 32 | Run all comparison benchmarks: | ||
| 33 | ```bash | ||
| 34 | cd benchmarks/comparison | ||
| 35 | go test -bench=. -benchmem -benchtime=1s | ||
| 36 | ``` | ||
| 37 | |||
| 38 | ### Specific Benchmark Groups | ||
| 39 | |||
| 40 | Event unmarshaling: | ||
| 41 | ```bash | ||
| 42 | cd benchmarks/comparison | ||
| 43 | go test -bench=BenchmarkEventUnmarshal -benchmem | ||
| 44 | ``` | ||
| 45 | |||
| 46 | Event signing: | ||
| 47 | ```bash | ||
| 48 | cd benchmarks/comparison | ||
| 49 | go test -bench=BenchmarkEventSign -benchmem | ||
| 50 | ``` | ||
| 51 | |||
| 52 | Event verification: | ||
| 53 | ```bash | ||
| 54 | cd benchmarks/comparison | ||
| 55 | go test -bench=BenchmarkEventVerify -benchmem | ||
| 56 | ``` | ||
| 57 | |||
| 58 | Filter matching: | ||
| 59 | ```bash | ||
| 60 | cd benchmarks/comparison | ||
| 61 | go test -bench=BenchmarkFilterMatch -benchmem | ||
| 62 | ``` | ||
| 63 | |||
| 64 | ### Compare Single Library | ||
| 65 | |||
| 66 | NWIO only: | ||
| 67 | ```bash | ||
| 68 | cd benchmarks/comparison | ||
| 69 | go test -bench='.*_NWIO' -benchmem | ||
| 70 | ``` | ||
| 71 | |||
| 72 | NBD only: | ||
| 73 | ```bash | ||
| 74 | cd benchmarks/comparison | ||
| 75 | go test -bench='.*_NBD' -benchmem | ||
| 76 | ``` | ||
| 77 | |||
| 78 | Fiat only: | ||
| 79 | ```bash | ||
| 80 | cd benchmarks/comparison | ||
| 81 | go test -bench='.*_Fiat' -benchmem | ||
| 82 | ``` | ||
| 83 | |||
| 84 | ## Analyzing Results | ||
| 85 | |||
| 86 | Use `benchstat` for statistical analysis: | ||
| 87 | |||
| 88 | ```bash | ||
| 89 | # Install benchstat | ||
| 90 | go install golang.org/x/perf/cmd/benchstat@latest | ||
| 91 | |||
| 92 | # Run benchmarks multiple times and compare | ||
| 93 | cd benchmarks/comparison | ||
| 94 | go test -bench=. -benchmem -count=10 > results.txt | ||
| 95 | benchstat results.txt | ||
| 96 | ``` | ||
| 97 | |||
| 98 | Compare two specific libraries: | ||
| 99 | ```bash | ||
| 100 | cd benchmarks/comparison | ||
| 101 | go test -bench='.*_NWIO' -benchmem -count=10 > nwio.txt | ||
| 102 | go test -bench='.*_NBD' -benchmem -count=10 > nbd.txt | ||
| 103 | benchstat nwio.txt nbd.txt | ||
| 104 | ``` | ||
| 105 | |||
| 106 | ## Understanding the Output | ||
| 107 | |||
| 108 | Example output: | ||
| 109 | ``` | ||
| 110 | BenchmarkEventSign_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 | |||
| 120 | 1. **Event Unmarshaling**: Critical for relay implementations | ||
| 121 | 2. **Event Signing**: Important for client implementations | ||
| 122 | 3. **Event Verification**: Critical for all implementations | ||
| 123 | 4. **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 | ||
