diff options
| author | bndw <ben@bdw.to> | 2026-02-14 18:56:19 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-02-14 18:56:19 -0800 |
| commit | 7a5d5a53e5d6878f38382c4d35f644e088d318d2 (patch) | |
| tree | 5f8ba0bee800a5998ec4167c47e4adc6602243e1 | |
| parent | 7fba76d7e4e63e0c29da81d6be43330743af1aaf (diff) | |
feat: add library comparison benchmarks with build tag isolation
Add comprehensive benchmarks comparing NWIO against nbd-wtf/go-nostr and
fiatjaf.com/nostr across event operations, signing, verification, and filtering.
Use build tag 'benchcmp' to prevent competitor libraries from polluting module
dependencies - they're only downloaded when explicitly running comparison tests.
| -rw-r--r-- | BENCHMARKS.md | 129 | ||||
| -rw-r--r-- | BENCHMARK_SUMMARY.md | 154 | ||||
| -rw-r--r-- | benchmark_results.txt | 32 | ||||
| -rw-r--r-- | comparison_bench_test.go | 512 | ||||
| -rw-r--r-- | go.mod | 10 | ||||
| -rw-r--r-- | go.sum | 16 | ||||
| -rwxr-xr-x | run_benchmarks.sh | 35 |
7 files changed, 875 insertions, 13 deletions
diff --git a/BENCHMARKS.md b/BENCHMARKS.md new file mode 100644 index 0000000..14a861c --- /dev/null +++ b/BENCHMARKS.md | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | # Nostr Library Benchmarks | ||
| 2 | |||
| 3 | This directory contains comprehensive benchmarks comparing three popular Go Nostr libraries: | ||
| 4 | |||
| 5 | - **NWIO** (`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 require the `benchcmp` build tag to avoid polluting the module dependencies with competitor libraries. | ||
| 29 | |||
| 30 | ### Quick Start | ||
| 31 | |||
| 32 | Run all benchmarks (automatically handles dependencies): | ||
| 33 | ```bash | ||
| 34 | ./run_benchmarks.sh | ||
| 35 | ``` | ||
| 36 | |||
| 37 | Or manually: | ||
| 38 | ```bash | ||
| 39 | # First, get the comparison dependencies | ||
| 40 | go get -tags=benchcmp -t ./... | ||
| 41 | |||
| 42 | # Then run the benchmarks | ||
| 43 | go test -tags=benchcmp -bench=. -benchmem -benchtime=1s | ||
| 44 | ``` | ||
| 45 | |||
| 46 | ### Specific Benchmark Groups | ||
| 47 | |||
| 48 | Event unmarshaling: | ||
| 49 | ```bash | ||
| 50 | go test -tags=benchcmp -bench=BenchmarkEventUnmarshal -benchmem | ||
| 51 | ``` | ||
| 52 | |||
| 53 | Event signing: | ||
| 54 | ```bash | ||
| 55 | go test -tags=benchcmp -bench=BenchmarkEventSign -benchmem | ||
| 56 | ``` | ||
| 57 | |||
| 58 | Event verification: | ||
| 59 | ```bash | ||
| 60 | go test -tags=benchcmp -bench=BenchmarkEventVerify -benchmem | ||
| 61 | ``` | ||
| 62 | |||
| 63 | Filter matching: | ||
| 64 | ```bash | ||
| 65 | go test -tags=benchcmp -bench=BenchmarkFilterMatch -benchmem | ||
| 66 | ``` | ||
| 67 | |||
| 68 | ### Compare Single Library | ||
| 69 | |||
| 70 | NWIO only: | ||
| 71 | ```bash | ||
| 72 | go test -tags=benchcmp -bench='.*_NWIO' -benchmem | ||
| 73 | ``` | ||
| 74 | |||
| 75 | NBD only: | ||
| 76 | ```bash | ||
| 77 | go test -tags=benchcmp -bench='.*_NBD' -benchmem | ||
| 78 | ``` | ||
| 79 | |||
| 80 | Fiat only: | ||
| 81 | ```bash | ||
| 82 | go test -tags=benchcmp -bench='.*_Fiat' -benchmem | ||
| 83 | ``` | ||
| 84 | |||
| 85 | ## Analyzing Results | ||
| 86 | |||
| 87 | Use `benchstat` for statistical analysis: | ||
| 88 | |||
| 89 | ```bash | ||
| 90 | # Install benchstat | ||
| 91 | go install golang.org/x/perf/cmd/benchstat@latest | ||
| 92 | |||
| 93 | # Run benchmarks multiple times and compare | ||
| 94 | go test -tags=benchcmp -bench=. -benchmem -count=10 > results.txt | ||
| 95 | benchstat results.txt | ||
| 96 | ``` | ||
| 97 | |||
| 98 | Compare two specific libraries: | ||
| 99 | ```bash | ||
| 100 | go test -tags=benchcmp -bench='.*_NWIO' -benchmem -count=10 > nwio.txt | ||
| 101 | go test -tags=benchcmp -bench='.*_NBD' -benchmem -count=10 > nbd.txt | ||
| 102 | benchstat nwio.txt nbd.txt | ||
| 103 | ``` | ||
| 104 | |||
| 105 | ## Understanding the Output | ||
| 106 | |||
| 107 | Example output: | ||
| 108 | ``` | ||
| 109 | BenchmarkEventSign_NWIO-24 50000 35421 ns/op 1024 B/op 12 allocs/op | ||
| 110 | ``` | ||
| 111 | |||
| 112 | - `50000`: Number of iterations | ||
| 113 | - `35421 ns/op`: Nanoseconds per operation (lower is better) | ||
| 114 | - `1024 B/op`: Bytes allocated per operation (lower is better) | ||
| 115 | - `12 allocs/op`: Memory allocations per operation (lower is better) | ||
| 116 | |||
| 117 | ## Performance Tips | ||
| 118 | |||
| 119 | 1. **Event Unmarshaling**: Critical for relay implementations | ||
| 120 | 2. **Event Signing**: Important for client implementations | ||
| 121 | 3. **Event Verification**: Critical for all implementations | ||
| 122 | 4. **Filter Matching**: Important for relay implementations with many subscriptions | ||
| 123 | |||
| 124 | ## Notes | ||
| 125 | |||
| 126 | - All benchmarks use realistic event data | ||
| 127 | - Benchmarks run with default Go test timeout | ||
| 128 | - Results may vary based on hardware and system load | ||
| 129 | - Use `-benchtime=5s` for more stable results on noisy systems | ||
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 | |||
| 3 | Comparison 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 | ``` | ||
| 25 | NWIO: 2,541 ns/op 888 B/op 17 allocs/op ⭐ FASTEST, LOW MEMORY | ||
| 26 | NBD: 2,832 ns/op 944 B/op 13 allocs/op | ||
| 27 | Fiat: 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 | ``` | ||
| 33 | NWIO: 1,790 ns/op 1,010 B/op 3 allocs/op ⭐ FASTEST, LEAST ALLOCS | ||
| 34 | NBD: 1,819 ns/op 1,500 B/op 6 allocs/op | ||
| 35 | Fiat: 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 | ``` | ||
| 41 | NWIO: 391 ns/op 360 B/op 7 allocs/op | ||
| 42 | NBD: 129 ns/op 208 B/op 2 allocs/op ⭐ FASTEST, 3x faster | ||
| 43 | Fiat: 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 | ``` | ||
| 49 | NWIO: 608 ns/op 488 B/op 9 allocs/op | ||
| 50 | NBD: 302 ns/op 336 B/op 4 allocs/op | ||
| 51 | Fiat: 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 | ``` | ||
| 57 | NWIO: 37,689 ns/op 208 B/op 4 allocs/op | ||
| 58 | NBD: 470 ns/op 369 B/op 8 allocs/op ⭐ FASTEST, 80x faster! | ||
| 59 | Fiat: 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 | ``` | ||
| 65 | NWIO: 129,854 ns/op 2,363 B/op 42 allocs/op | ||
| 66 | NBD: 59,069 ns/op 2,112 B/op 35 allocs/op ⭐ TIED FASTEST | ||
| 67 | Fiat: 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 | ``` | ||
| 73 | NWIO: 99,744 ns/op 953 B/op 19 allocs/op ⭐ FASTEST | ||
| 74 | NBD: 105,995 ns/op 624 B/op 11 allocs/op ⭐ LEAST MEMORY | ||
| 75 | Fiat: 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 | ``` | ||
| 81 | NWIO: 7.1 ns/op 0 B/op 0 allocs/op ⭐ FASTEST, 2x faster | ||
| 82 | NBD: 10.8 ns/op 0 B/op 0 allocs/op | ||
| 83 | Fiat: 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 | ``` | ||
| 89 | NWIO: 30.9 ns/op 0 B/op 0 allocs/op ⭐ FASTEST | ||
| 90 | NBD: 33.4 ns/op 0 B/op 0 allocs/op | ||
| 91 | Fiat: 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 🔴 | ||
| 98 | 1. **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 | |||
| 103 | 2. **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 🟡 | ||
| 109 | 3. **Event Serialization** - 3x slower than NBD | ||
| 110 | - Current: 391 ns | ||
| 111 | - Target: ~130 ns (match NBD) | ||
| 112 | - Impact: Used in ID computation | ||
| 113 | |||
| 114 | 4. **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 | |||
| 121 | 1. **Filter Matching** - 2x faster than Fiat, fastest overall | ||
| 122 | 2. **Event Marshaling** - Fastest with minimal allocations | ||
| 123 | 3. **Event Verification** - Slightly faster than competitors | ||
| 124 | 4. **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 | ||
| 148 | go test -bench=BenchmarkEventSign -benchmem comparison_bench_test.go | ||
| 149 | go test -bench=BenchmarkFilterMatch -benchmem comparison_bench_test.go | ||
| 150 | |||
| 151 | # Statistical analysis with benchstat | ||
| 152 | go test -bench=. -count=10 comparison_bench_test.go > results.txt | ||
| 153 | benchstat results.txt | ||
| 154 | ``` | ||
diff --git a/benchmark_results.txt b/benchmark_results.txt new file mode 100644 index 0000000..c3976e6 --- /dev/null +++ b/benchmark_results.txt | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | goos: linux | ||
| 2 | goarch: amd64 | ||
| 3 | cpu: AMD Ryzen AI 9 HX PRO 370 w/ Radeon 890M | ||
| 4 | BenchmarkEventUnmarshal_NWIO-24 498826 2541 ns/op 888 B/op 17 allocs/op | ||
| 5 | BenchmarkEventUnmarshal_NBD-24 423019 2832 ns/op 944 B/op 13 allocs/op | ||
| 6 | BenchmarkEventUnmarshal_Fiat-24 430042 2545 ns/op 752 B/op 10 allocs/op | ||
| 7 | BenchmarkEventMarshal_NWIO-24 613165 1790 ns/op 1010 B/op 3 allocs/op | ||
| 8 | BenchmarkEventMarshal_NBD-24 620986 1819 ns/op 1500 B/op 6 allocs/op | ||
| 9 | BenchmarkEventMarshal_Fiat-24 621964 1971 ns/op 2254 B/op 13 allocs/op | ||
| 10 | BenchmarkEventSerialize_NWIO-24 3059661 391.0 ns/op 360 B/op 7 allocs/op | ||
| 11 | BenchmarkEventSerialize_NBD-24 8824029 128.8 ns/op 208 B/op 2 allocs/op | ||
| 12 | BenchmarkEventSerialize_Fiat-24 6533536 160.9 ns/op 400 B/op 3 allocs/op | ||
| 13 | BenchmarkComputeID_NWIO-24 2108437 608.0 ns/op 488 B/op 9 allocs/op | ||
| 14 | BenchmarkComputeID_NBD-24 4072243 302.2 ns/op 336 B/op 4 allocs/op | ||
| 15 | BenchmarkComputeID_Fiat-24 4421660 275.9 ns/op 400 B/op 3 allocs/op | ||
| 16 | BenchmarkGenerateKey_NWIO-24 31942 37689 ns/op 208 B/op 4 allocs/op | ||
| 17 | BenchmarkGenerateKey_NBD-24 2489169 469.6 ns/op 369 B/op 8 allocs/op | ||
| 18 | BenchmarkGenerateKey_Fiat-24 45475 25375 ns/op 272 B/op 5 allocs/op | ||
| 19 | BenchmarkEventSign_NWIO-24 9072 129854 ns/op 2363 B/op 42 allocs/op | ||
| 20 | BenchmarkEventSign_NBD-24 20325 59069 ns/op 2112 B/op 35 allocs/op | ||
| 21 | BenchmarkEventSign_Fiat-24 20613 58572 ns/op 1760 B/op 29 allocs/op | ||
| 22 | BenchmarkEventVerify_NWIO-24 12009 99744 ns/op 953 B/op 19 allocs/op | ||
| 23 | BenchmarkEventVerify_NBD-24 10000 105995 ns/op 624 B/op 11 allocs/op | ||
| 24 | BenchmarkEventVerify_Fiat-24 10000 103744 ns/op 640 B/op 9 allocs/op | ||
| 25 | BenchmarkFilterMatch_NWIO-24 167376669 7.091 ns/op 0 B/op 0 allocs/op | ||
| 26 | BenchmarkFilterMatch_NBD-24 100000000 10.82 ns/op 0 B/op 0 allocs/op | ||
| 27 | BenchmarkFilterMatch_Fiat-24 71761591 16.40 ns/op 0 B/op 0 allocs/op | ||
| 28 | BenchmarkFilterMatchComplex_NWIO-24 39214178 30.88 ns/op 0 B/op 0 allocs/op | ||
| 29 | BenchmarkFilterMatchComplex_NBD-24 35580048 33.40 ns/op 0 B/op 0 allocs/op | ||
| 30 | BenchmarkFilterMatchComplex_Fiat-24 28026481 42.64 ns/op 0 B/op 0 allocs/op | ||
| 31 | PASS | ||
| 32 | ok command-line-arguments 40.651s | ||
diff --git a/comparison_bench_test.go b/comparison_bench_test.go new file mode 100644 index 0000000..ee3e936 --- /dev/null +++ b/comparison_bench_test.go | |||
| @@ -0,0 +1,512 @@ | |||
| 1 | //go:build benchcmp | ||
| 2 | |||
| 3 | package nostr_test | ||
| 4 | |||
| 5 | import ( | ||
| 6 | "encoding/hex" | ||
| 7 | "encoding/json" | ||
| 8 | "testing" | ||
| 9 | |||
| 10 | nwio "northwest.io/nostr" | ||
| 11 | nbd "github.com/nbd-wtf/go-nostr" | ||
| 12 | fiat "fiatjaf.com/nostr" | ||
| 13 | ) | ||
| 14 | |||
| 15 | // Sample event data for benchmarks | ||
| 16 | var ( | ||
| 17 | samplePubKey = "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d" | ||
| 18 | sampleSig = "230e9d8f0ddaf7eb70b5f7741ccfa37e87a455c9a469282e3464e2052d3192cd63a167e196e381ef9d7e69e9ea43af2b0d0e1b8f1e6e7c4e1c6e8e3e9e8e3e9e8" | ||
| 19 | sampleID = "d42c96ccac39e0113b2ef8df82e82e2e15e0e1e7e9e5e7e1e7e9e5e7e1e7e9e5" | ||
| 20 | |||
| 21 | sampleEventJSON = `{ | ||
| 22 | "id": "d42c96ccac39e0113b2ef8df82e82e2e15e0e1e7e9e5e7e1e7e9e5e7e1e7e9e5", | ||
| 23 | "pubkey": "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d", | ||
| 24 | "created_at": 1672531200, | ||
| 25 | "kind": 1, | ||
| 26 | "tags": [["e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36", "wss://nostr.example.com"]], | ||
| 27 | "content": "Hello Nostr!", | ||
| 28 | "sig": "230e9d8f0ddaf7eb70b5f7741ccfa37e87a455c9a469282e3464e2052d3192cd63a167e196e381ef9d7e69e9ea43af2b0d0e1b8f1e6e7c4e1c6e8e3e9e8e3e9e8" | ||
| 29 | }` | ||
| 30 | ) | ||
| 31 | |||
| 32 | // ============================================================================ | ||
| 33 | // Event Unmarshaling Benchmarks | ||
| 34 | // ============================================================================ | ||
| 35 | |||
| 36 | func BenchmarkEventUnmarshal_NWIO(b *testing.B) { | ||
| 37 | data := []byte(sampleEventJSON) | ||
| 38 | b.ResetTimer() | ||
| 39 | for i := 0; i < b.N; i++ { | ||
| 40 | var evt nwio.Event | ||
| 41 | if err := json.Unmarshal(data, &evt); err != nil { | ||
| 42 | b.Fatal(err) | ||
| 43 | } | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | func BenchmarkEventUnmarshal_NBD(b *testing.B) { | ||
| 48 | data := []byte(sampleEventJSON) | ||
| 49 | b.ResetTimer() | ||
| 50 | for i := 0; i < b.N; i++ { | ||
| 51 | var evt nbd.Event | ||
| 52 | if err := json.Unmarshal(data, &evt); err != nil { | ||
| 53 | b.Fatal(err) | ||
| 54 | } | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | func BenchmarkEventUnmarshal_Fiat(b *testing.B) { | ||
| 59 | data := []byte(sampleEventJSON) | ||
| 60 | b.ResetTimer() | ||
| 61 | for i := 0; i < b.N; i++ { | ||
| 62 | var evt fiat.Event | ||
| 63 | if err := json.Unmarshal(data, &evt); err != nil { | ||
| 64 | b.Fatal(err) | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | // ============================================================================ | ||
| 70 | // Event Marshaling Benchmarks | ||
| 71 | // ============================================================================ | ||
| 72 | |||
| 73 | func BenchmarkEventMarshal_NWIO(b *testing.B) { | ||
| 74 | evt := &nwio.Event{ | ||
| 75 | ID: sampleID, | ||
| 76 | PubKey: samplePubKey, | ||
| 77 | CreatedAt: 1672531200, | ||
| 78 | Kind: 1, | ||
| 79 | Tags: nwio.Tags{{"e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}}, | ||
| 80 | Content: "Hello Nostr!", | ||
| 81 | Sig: sampleSig, | ||
| 82 | } | ||
| 83 | b.ResetTimer() | ||
| 84 | for i := 0; i < b.N; i++ { | ||
| 85 | if _, err := json.Marshal(evt); err != nil { | ||
| 86 | b.Fatal(err) | ||
| 87 | } | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | func BenchmarkEventMarshal_NBD(b *testing.B) { | ||
| 92 | evt := &nbd.Event{ | ||
| 93 | ID: sampleID, | ||
| 94 | PubKey: samplePubKey, | ||
| 95 | CreatedAt: nbd.Timestamp(1672531200), | ||
| 96 | Kind: 1, | ||
| 97 | Tags: nbd.Tags{{"e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}}, | ||
| 98 | Content: "Hello Nostr!", | ||
| 99 | Sig: sampleSig, | ||
| 100 | } | ||
| 101 | b.ResetTimer() | ||
| 102 | for i := 0; i < b.N; i++ { | ||
| 103 | if _, err := json.Marshal(evt); err != nil { | ||
| 104 | b.Fatal(err) | ||
| 105 | } | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | func BenchmarkEventMarshal_Fiat(b *testing.B) { | ||
| 110 | sig, _ := hex.DecodeString(sampleSig) | ||
| 111 | var sigBytes [64]byte | ||
| 112 | copy(sigBytes[:], sig) | ||
| 113 | |||
| 114 | pubkey, _ := fiat.PubKeyFromHex(samplePubKey) | ||
| 115 | id, _ := fiat.IDFromHex(sampleID) | ||
| 116 | |||
| 117 | evt := &fiat.Event{ | ||
| 118 | ID: id, | ||
| 119 | PubKey: pubkey, | ||
| 120 | CreatedAt: fiat.Timestamp(1672531200), | ||
| 121 | Kind: 1, | ||
| 122 | Tags: fiat.Tags{{"e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}}, | ||
| 123 | Content: "Hello Nostr!", | ||
| 124 | Sig: sigBytes, | ||
| 125 | } | ||
| 126 | b.ResetTimer() | ||
| 127 | for i := 0; i < b.N; i++ { | ||
| 128 | if _, err := json.Marshal(evt); err != nil { | ||
| 129 | b.Fatal(err) | ||
| 130 | } | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | // ============================================================================ | ||
| 135 | // Event Serialization (for ID computation) Benchmarks | ||
| 136 | // ============================================================================ | ||
| 137 | |||
| 138 | func BenchmarkEventSerialize_NWIO(b *testing.B) { | ||
| 139 | evt := &nwio.Event{ | ||
| 140 | PubKey: samplePubKey, | ||
| 141 | CreatedAt: 1672531200, | ||
| 142 | Kind: 1, | ||
| 143 | Tags: nwio.Tags{{"e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}}, | ||
| 144 | Content: "Hello Nostr!", | ||
| 145 | } | ||
| 146 | b.ResetTimer() | ||
| 147 | for i := 0; i < b.N; i++ { | ||
| 148 | _ = evt.Serialize() | ||
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | func BenchmarkEventSerialize_NBD(b *testing.B) { | ||
| 153 | evt := &nbd.Event{ | ||
| 154 | PubKey: samplePubKey, | ||
| 155 | CreatedAt: nbd.Timestamp(1672531200), | ||
| 156 | Kind: 1, | ||
| 157 | Tags: nbd.Tags{{"e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}}, | ||
| 158 | Content: "Hello Nostr!", | ||
| 159 | } | ||
| 160 | b.ResetTimer() | ||
| 161 | for i := 0; i < b.N; i++ { | ||
| 162 | _ = evt.Serialize() | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | func BenchmarkEventSerialize_Fiat(b *testing.B) { | ||
| 167 | pubkey, _ := fiat.PubKeyFromHex(samplePubKey) | ||
| 168 | evt := &fiat.Event{ | ||
| 169 | PubKey: pubkey, | ||
| 170 | CreatedAt: fiat.Timestamp(1672531200), | ||
| 171 | Kind: 1, | ||
| 172 | Tags: fiat.Tags{{"e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}}, | ||
| 173 | Content: "Hello Nostr!", | ||
| 174 | } | ||
| 175 | b.ResetTimer() | ||
| 176 | for i := 0; i < b.N; i++ { | ||
| 177 | _ = evt.Serialize() | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | // ============================================================================ | ||
| 182 | // Event ID Computation Benchmarks | ||
| 183 | // ============================================================================ | ||
| 184 | |||
| 185 | func BenchmarkComputeID_NWIO(b *testing.B) { | ||
| 186 | evt := &nwio.Event{ | ||
| 187 | PubKey: samplePubKey, | ||
| 188 | CreatedAt: 1672531200, | ||
| 189 | Kind: 1, | ||
| 190 | Tags: nwio.Tags{{"e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}}, | ||
| 191 | Content: "Hello Nostr!", | ||
| 192 | } | ||
| 193 | b.ResetTimer() | ||
| 194 | for i := 0; i < b.N; i++ { | ||
| 195 | _ = evt.ComputeID() | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | func BenchmarkComputeID_NBD(b *testing.B) { | ||
| 200 | evt := &nbd.Event{ | ||
| 201 | PubKey: samplePubKey, | ||
| 202 | CreatedAt: nbd.Timestamp(1672531200), | ||
| 203 | Kind: 1, | ||
| 204 | Tags: nbd.Tags{{"e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}}, | ||
| 205 | Content: "Hello Nostr!", | ||
| 206 | } | ||
| 207 | b.ResetTimer() | ||
| 208 | for i := 0; i < b.N; i++ { | ||
| 209 | _ = evt.GetID() | ||
| 210 | } | ||
| 211 | } | ||
| 212 | |||
| 213 | func BenchmarkComputeID_Fiat(b *testing.B) { | ||
| 214 | pubkey, _ := fiat.PubKeyFromHex(samplePubKey) | ||
| 215 | evt := &fiat.Event{ | ||
| 216 | PubKey: pubkey, | ||
| 217 | CreatedAt: fiat.Timestamp(1672531200), | ||
| 218 | Kind: 1, | ||
| 219 | Tags: fiat.Tags{{"e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}}, | ||
| 220 | Content: "Hello Nostr!", | ||
| 221 | } | ||
| 222 | b.ResetTimer() | ||
| 223 | for i := 0; i < b.N; i++ { | ||
| 224 | _ = evt.GetID() | ||
| 225 | } | ||
| 226 | } | ||
| 227 | |||
| 228 | // ============================================================================ | ||
| 229 | // Key Generation Benchmarks | ||
| 230 | // ============================================================================ | ||
| 231 | |||
| 232 | func BenchmarkGenerateKey_NWIO(b *testing.B) { | ||
| 233 | for i := 0; i < b.N; i++ { | ||
| 234 | if _, err := nwio.GenerateKey(); err != nil { | ||
| 235 | b.Fatal(err) | ||
| 236 | } | ||
| 237 | } | ||
| 238 | } | ||
| 239 | |||
| 240 | func BenchmarkGenerateKey_NBD(b *testing.B) { | ||
| 241 | for i := 0; i < b.N; i++ { | ||
| 242 | _ = nbd.GeneratePrivateKey() | ||
| 243 | } | ||
| 244 | } | ||
| 245 | |||
| 246 | func BenchmarkGenerateKey_Fiat(b *testing.B) { | ||
| 247 | for i := 0; i < b.N; i++ { | ||
| 248 | _ = fiat.Generate() | ||
| 249 | } | ||
| 250 | } | ||
| 251 | |||
| 252 | // ============================================================================ | ||
| 253 | // Event Signing Benchmarks | ||
| 254 | // ============================================================================ | ||
| 255 | |||
| 256 | func BenchmarkEventSign_NWIO(b *testing.B) { | ||
| 257 | key, err := nwio.GenerateKey() | ||
| 258 | if err != nil { | ||
| 259 | b.Fatal(err) | ||
| 260 | } | ||
| 261 | b.ResetTimer() | ||
| 262 | |||
| 263 | for i := 0; i < b.N; i++ { | ||
| 264 | evt := &nwio.Event{ | ||
| 265 | CreatedAt: 1672531200, | ||
| 266 | Kind: 1, | ||
| 267 | Tags: nwio.Tags{}, | ||
| 268 | Content: "Hello Nostr!", | ||
| 269 | } | ||
| 270 | if err := key.Sign(evt); err != nil { | ||
| 271 | b.Fatal(err) | ||
| 272 | } | ||
| 273 | } | ||
| 274 | } | ||
| 275 | |||
| 276 | func BenchmarkEventSign_NBD(b *testing.B) { | ||
| 277 | sk := nbd.GeneratePrivateKey() | ||
| 278 | b.ResetTimer() | ||
| 279 | |||
| 280 | for i := 0; i < b.N; i++ { | ||
| 281 | evt := &nbd.Event{ | ||
| 282 | CreatedAt: nbd.Timestamp(1672531200), | ||
| 283 | Kind: 1, | ||
| 284 | Tags: nbd.Tags{}, | ||
| 285 | Content: "Hello Nostr!", | ||
| 286 | } | ||
| 287 | if err := evt.Sign(sk); err != nil { | ||
| 288 | b.Fatal(err) | ||
| 289 | } | ||
| 290 | } | ||
| 291 | } | ||
| 292 | |||
| 293 | func BenchmarkEventSign_Fiat(b *testing.B) { | ||
| 294 | sk := fiat.Generate() | ||
| 295 | b.ResetTimer() | ||
| 296 | |||
| 297 | for i := 0; i < b.N; i++ { | ||
| 298 | evt := &fiat.Event{ | ||
| 299 | CreatedAt: fiat.Timestamp(1672531200), | ||
| 300 | Kind: 1, | ||
| 301 | Tags: fiat.Tags{}, | ||
| 302 | Content: "Hello Nostr!", | ||
| 303 | } | ||
| 304 | if err := evt.Sign(sk); err != nil { | ||
| 305 | b.Fatal(err) | ||
| 306 | } | ||
| 307 | } | ||
| 308 | } | ||
| 309 | |||
| 310 | // ============================================================================ | ||
| 311 | // Event Verification Benchmarks | ||
| 312 | // ============================================================================ | ||
| 313 | |||
| 314 | func BenchmarkEventVerify_NWIO(b *testing.B) { | ||
| 315 | // Create and sign an event | ||
| 316 | key, _ := nwio.GenerateKey() | ||
| 317 | evt := &nwio.Event{ | ||
| 318 | CreatedAt: 1672531200, | ||
| 319 | Kind: 1, | ||
| 320 | Tags: nwio.Tags{}, | ||
| 321 | Content: "Hello Nostr!", | ||
| 322 | } | ||
| 323 | key.Sign(evt) | ||
| 324 | |||
| 325 | b.ResetTimer() | ||
| 326 | for i := 0; i < b.N; i++ { | ||
| 327 | if !evt.Verify() { | ||
| 328 | b.Fatal("verification failed") | ||
| 329 | } | ||
| 330 | } | ||
| 331 | } | ||
| 332 | |||
| 333 | func BenchmarkEventVerify_NBD(b *testing.B) { | ||
| 334 | // Create and sign an event | ||
| 335 | sk := nbd.GeneratePrivateKey() | ||
| 336 | evt := &nbd.Event{ | ||
| 337 | CreatedAt: nbd.Timestamp(1672531200), | ||
| 338 | Kind: 1, | ||
| 339 | Tags: nbd.Tags{}, | ||
| 340 | Content: "Hello Nostr!", | ||
| 341 | } | ||
| 342 | evt.Sign(sk) | ||
| 343 | |||
| 344 | b.ResetTimer() | ||
| 345 | for i := 0; i < b.N; i++ { | ||
| 346 | if ok, _ := evt.CheckSignature(); !ok { | ||
| 347 | b.Fatal("verification failed") | ||
| 348 | } | ||
| 349 | } | ||
| 350 | } | ||
| 351 | |||
| 352 | func BenchmarkEventVerify_Fiat(b *testing.B) { | ||
| 353 | // Create and sign an event | ||
| 354 | sk := fiat.Generate() | ||
| 355 | evt := &fiat.Event{ | ||
| 356 | CreatedAt: fiat.Timestamp(1672531200), | ||
| 357 | Kind: 1, | ||
| 358 | Tags: fiat.Tags{}, | ||
| 359 | Content: "Hello Nostr!", | ||
| 360 | } | ||
| 361 | evt.Sign(sk) | ||
| 362 | |||
| 363 | b.ResetTimer() | ||
| 364 | for i := 0; i < b.N; i++ { | ||
| 365 | if !evt.VerifySignature() { | ||
| 366 | b.Fatal("verification failed") | ||
| 367 | } | ||
| 368 | } | ||
| 369 | } | ||
| 370 | |||
| 371 | // ============================================================================ | ||
| 372 | // Filter Matching Benchmarks | ||
| 373 | // ============================================================================ | ||
| 374 | |||
| 375 | func BenchmarkFilterMatch_NWIO(b *testing.B) { | ||
| 376 | filter := &nwio.Filter{ | ||
| 377 | Kinds: []int{1}, | ||
| 378 | Authors: []string{samplePubKey}, | ||
| 379 | } | ||
| 380 | evt := &nwio.Event{ | ||
| 381 | PubKey: samplePubKey, | ||
| 382 | CreatedAt: 1672531200, | ||
| 383 | Kind: 1, | ||
| 384 | Content: "Hello Nostr!", | ||
| 385 | } | ||
| 386 | |||
| 387 | b.ResetTimer() | ||
| 388 | for i := 0; i < b.N; i++ { | ||
| 389 | if !filter.Matches(evt) { | ||
| 390 | b.Fatal("filter should match") | ||
| 391 | } | ||
| 392 | } | ||
| 393 | } | ||
| 394 | |||
| 395 | func BenchmarkFilterMatch_NBD(b *testing.B) { | ||
| 396 | filter := nbd.Filter{ | ||
| 397 | Kinds: []int{1}, | ||
| 398 | Authors: []string{samplePubKey}, | ||
| 399 | } | ||
| 400 | evt := &nbd.Event{ | ||
| 401 | PubKey: samplePubKey, | ||
| 402 | CreatedAt: nbd.Timestamp(1672531200), | ||
| 403 | Kind: 1, | ||
| 404 | Content: "Hello Nostr!", | ||
| 405 | } | ||
| 406 | |||
| 407 | b.ResetTimer() | ||
| 408 | for i := 0; i < b.N; i++ { | ||
| 409 | if !filter.Matches(evt) { | ||
| 410 | b.Fatal("filter should match") | ||
| 411 | } | ||
| 412 | } | ||
| 413 | } | ||
| 414 | |||
| 415 | func BenchmarkFilterMatch_Fiat(b *testing.B) { | ||
| 416 | pubkey, _ := fiat.PubKeyFromHex(samplePubKey) | ||
| 417 | filter := fiat.Filter{ | ||
| 418 | Kinds: []fiat.Kind{1}, | ||
| 419 | Authors: []fiat.PubKey{pubkey}, | ||
| 420 | } | ||
| 421 | evt := &fiat.Event{ | ||
| 422 | PubKey: pubkey, | ||
| 423 | CreatedAt: fiat.Timestamp(1672531200), | ||
| 424 | Kind: 1, | ||
| 425 | Content: "Hello Nostr!", | ||
| 426 | } | ||
| 427 | |||
| 428 | b.ResetTimer() | ||
| 429 | for i := 0; i < b.N; i++ { | ||
| 430 | if !filter.Matches(*evt) { | ||
| 431 | b.Fatal("filter should match") | ||
| 432 | } | ||
| 433 | } | ||
| 434 | } | ||
| 435 | |||
| 436 | // ============================================================================ | ||
| 437 | // Complex Filter Matching Benchmarks (with tags) | ||
| 438 | // ============================================================================ | ||
| 439 | |||
| 440 | func BenchmarkFilterMatchComplex_NWIO(b *testing.B) { | ||
| 441 | filter := &nwio.Filter{ | ||
| 442 | Kinds: []int{1, 6, 7}, | ||
| 443 | Authors: []string{samplePubKey[:8]}, // Prefix match | ||
| 444 | Tags: map[string][]string{ | ||
| 445 | "e": {"5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}, | ||
| 446 | }, | ||
| 447 | } | ||
| 448 | evt := &nwio.Event{ | ||
| 449 | PubKey: samplePubKey, | ||
| 450 | CreatedAt: 1672531200, | ||
| 451 | Kind: 1, | ||
| 452 | Tags: nwio.Tags{{"e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}}, | ||
| 453 | Content: "Hello Nostr!", | ||
| 454 | } | ||
| 455 | |||
| 456 | b.ResetTimer() | ||
| 457 | for i := 0; i < b.N; i++ { | ||
| 458 | if !filter.Matches(evt) { | ||
| 459 | b.Fatal("filter should match") | ||
| 460 | } | ||
| 461 | } | ||
| 462 | } | ||
| 463 | |||
| 464 | func BenchmarkFilterMatchComplex_NBD(b *testing.B) { | ||
| 465 | filter := nbd.Filter{ | ||
| 466 | Kinds: []int{1, 6, 7}, | ||
| 467 | Authors: []string{samplePubKey}, // NBD also supports prefix, use full key for simplicity | ||
| 468 | Tags: nbd.TagMap{ | ||
| 469 | "e": []string{"5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}, | ||
| 470 | }, | ||
| 471 | } | ||
| 472 | evt := &nbd.Event{ | ||
| 473 | PubKey: samplePubKey, | ||
| 474 | CreatedAt: nbd.Timestamp(1672531200), | ||
| 475 | Kind: 1, | ||
| 476 | Tags: nbd.Tags{{"e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}}, | ||
| 477 | Content: "Hello Nostr!", | ||
| 478 | } | ||
| 479 | |||
| 480 | b.ResetTimer() | ||
| 481 | for i := 0; i < b.N; i++ { | ||
| 482 | if !filter.Matches(evt) { | ||
| 483 | b.Fatal("filter should match") | ||
| 484 | } | ||
| 485 | } | ||
| 486 | } | ||
| 487 | |||
| 488 | func BenchmarkFilterMatchComplex_Fiat(b *testing.B) { | ||
| 489 | pubkey, _ := fiat.PubKeyFromHex(samplePubKey) | ||
| 490 | |||
| 491 | filter := fiat.Filter{ | ||
| 492 | Kinds: []fiat.Kind{1, 6, 7}, | ||
| 493 | Authors: []fiat.PubKey{pubkey}, // Use full pubkey for simplicity | ||
| 494 | Tags: fiat.TagMap{ | ||
| 495 | "e": []string{"5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}, | ||
| 496 | }, | ||
| 497 | } | ||
| 498 | evt := &fiat.Event{ | ||
| 499 | PubKey: pubkey, | ||
| 500 | CreatedAt: fiat.Timestamp(1672531200), | ||
| 501 | Kind: 1, | ||
| 502 | Tags: fiat.Tags{{"e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"}}, | ||
| 503 | Content: "Hello Nostr!", | ||
| 504 | } | ||
| 505 | |||
| 506 | b.ResetTimer() | ||
| 507 | for i := 0; i < b.N; i++ { | ||
| 508 | if !filter.Matches(*evt) { | ||
| 509 | b.Fatal("filter should match") | ||
| 510 | } | ||
| 511 | } | ||
| 512 | } | ||
| @@ -1,11 +1,11 @@ | |||
| 1 | module northwest.io/nostr | 1 | module northwest.io/nostr |
| 2 | 2 | ||
| 3 | go 1.21 | 3 | go 1.25 |
| 4 | 4 | ||
| 5 | require github.com/btcsuite/btcd/btcec/v2 v2.3.2 | 5 | require github.com/btcsuite/btcd/btcec/v2 v2.3.4 |
| 6 | 6 | ||
| 7 | require ( | 7 | require ( |
| 8 | github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect | 8 | github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect |
| 9 | github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect | 9 | github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect |
| 10 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect | 10 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect |
| 11 | ) | 11 | ) |
| @@ -1,10 +1,10 @@ | |||
| 1 | github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= | 1 | github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ= |
| 2 | github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= | 2 | github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= |
| 3 | github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= | 3 | github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ= |
| 4 | github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= | 4 | github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= |
| 5 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | 5 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= |
| 6 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | 6 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
| 7 | github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= | 7 | github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8= |
| 8 | github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= | 8 | github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= |
| 9 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc= | 9 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc= |
| 10 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= | 10 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40= |
diff --git a/run_benchmarks.sh b/run_benchmarks.sh new file mode 100755 index 0000000..87dfd17 --- /dev/null +++ b/run_benchmarks.sh | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | set -e | ||
| 3 | |||
| 4 | # Colors for output | ||
| 5 | GREEN='\033[0;32m' | ||
| 6 | BLUE='\033[0;34m' | ||
| 7 | YELLOW='\033[1;33m' | ||
| 8 | NC='\033[0m' # No Color | ||
| 9 | |||
| 10 | echo -e "${BLUE}Running Nostr Library Benchmarks${NC}" | ||
| 11 | echo -e "${BLUE}Comparing: NWIO vs NBD-WTF vs Fiatjaf${NC}" | ||
| 12 | echo "" | ||
| 13 | |||
| 14 | # First, install comparison dependencies if needed | ||
| 15 | echo -e "${YELLOW}Ensuring comparison dependencies are available...${NC}" | ||
| 16 | go get -tags=benchcmp -t ./... | ||
| 17 | echo "" | ||
| 18 | |||
| 19 | # Run all benchmarks with the benchcmp build tag | ||
| 20 | echo -e "${GREEN}Running all benchmarks...${NC}" | ||
| 21 | go test -tags=benchcmp -bench=. -benchmem -benchtime=1s -run=^$ | tee benchmark_results.txt | ||
| 22 | |||
| 23 | echo "" | ||
| 24 | echo -e "${GREEN}Results saved to benchmark_results.txt${NC}" | ||
| 25 | echo "" | ||
| 26 | echo -e "${BLUE}To run specific benchmark groups:${NC}" | ||
| 27 | echo " go test -tags=benchcmp -bench=BenchmarkEventUnmarshal -benchmem" | ||
| 28 | echo " go test -tags=benchcmp -bench=BenchmarkEventSign -benchmem" | ||
| 29 | echo " go test -tags=benchcmp -bench=BenchmarkEventVerify -benchmem" | ||
| 30 | echo " go test -tags=benchcmp -bench=BenchmarkFilterMatch -benchmem" | ||
| 31 | echo "" | ||
| 32 | echo -e "${BLUE}To compare specific libraries:${NC}" | ||
| 33 | echo " go test -tags=benchcmp -bench='.*_NWIO' -benchmem" | ||
| 34 | echo " go test -tags=benchcmp -bench='.*_NBD' -benchmem" | ||
| 35 | echo " go test -tags=benchcmp -bench='.*_Fiat' -benchmem" | ||
