diff options
| author | bndw <ben@bdw.to> | 2026-02-16 10:58:11 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-02-16 10:58:11 -0800 |
| commit | 4b7dfe1e7764d8424b1be935c7fea09a102382e8 (patch) | |
| tree | bd80dc38b0c3d9e4332b9f5df25c17fb4943ea64 /comparison_bench_test.go | |
| parent | 7a5d5a53e5d6878f38382c4d35f644e088d318d2 (diff) | |
fix: cleanup bench
Diffstat (limited to 'comparison_bench_test.go')
| -rw-r--r-- | comparison_bench_test.go | 512 |
1 files changed, 0 insertions, 512 deletions
diff --git a/comparison_bench_test.go b/comparison_bench_test.go deleted file mode 100644 index ee3e936..0000000 --- a/comparison_bench_test.go +++ /dev/null | |||
| @@ -1,512 +0,0 @@ | |||
| 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 | } | ||
