go mod tidy works now at least.
This commit is contained in:
@@ -7,12 +7,11 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"fiatjaf.com/nostr"
|
||||
"fiatjaf.com/nostr/eventstore"
|
||||
"fiatjaf.com/nostr/eventstore/badger"
|
||||
"fiatjaf.com/nostr/eventstore/lmdb"
|
||||
"fiatjaf.com/nostr/eventstore/slicestore"
|
||||
"fiatjaf.com/nostr/eventstore/sqlite3"
|
||||
"fiatjaf.com/nostr"
|
||||
)
|
||||
|
||||
func BenchmarkSliceStore(b *testing.B) {
|
||||
@@ -35,61 +34,53 @@ func BenchmarkBadger(b *testing.B) {
|
||||
runBenchmarkOn(b, d)
|
||||
}
|
||||
|
||||
func BenchmarkSQLite(b *testing.B) {
|
||||
os.RemoveAll(dbpath + "sqlite")
|
||||
q := &sqlite3.SQLite3Backend{DatabaseURL: dbpath + "sqlite", QueryTagsLimit: 50}
|
||||
q.Init()
|
||||
|
||||
runBenchmarkOn(b, q)
|
||||
}
|
||||
|
||||
func runBenchmarkOn(b *testing.B, db eventstore.Store) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
eTag := make([]byte, 32)
|
||||
binary.BigEndian.PutUint16(eTag, uint16(i))
|
||||
|
||||
ref, _ := nostr.GetPublicKey(sk3)
|
||||
ref := nostr.GetPublicKey(sk3)
|
||||
if i%3 == 0 {
|
||||
ref, _ = nostr.GetPublicKey(sk4)
|
||||
ref = nostr.GetPublicKey(sk4)
|
||||
}
|
||||
|
||||
evt := &nostr.Event{
|
||||
evt := nostr.Event{
|
||||
CreatedAt: nostr.Timestamp(i*10 + 2),
|
||||
Content: fmt.Sprintf("hello %d", i),
|
||||
Tags: nostr.Tags{
|
||||
{"t", fmt.Sprintf("t%d", i)},
|
||||
{"e", hex.EncodeToString(eTag)},
|
||||
{"p", ref},
|
||||
{"p", ref.Hex()},
|
||||
},
|
||||
Kind: i % 10,
|
||||
Kind: uint16(i % 10),
|
||||
}
|
||||
sk := sk3
|
||||
if i%3 == 0 {
|
||||
sk = sk4
|
||||
}
|
||||
evt.Sign(sk)
|
||||
db.SaveEvent(ctx, evt)
|
||||
db.SaveEvent(evt)
|
||||
}
|
||||
|
||||
filters := make([]nostr.Filter, 0, 10)
|
||||
filters = append(filters, nostr.Filter{Kinds: []int{1, 4, 8, 16}})
|
||||
pk3, _ := nostr.GetPublicKey(sk3)
|
||||
filters = append(filters, nostr.Filter{Authors: []string{pk3, nostr.GeneratePrivateKey()}})
|
||||
filters = append(filters, nostr.Filter{Authors: []string{pk3, nostr.GeneratePrivateKey()}, Kinds: []int{3, 4}})
|
||||
filters = append(filters, nostr.Filter{Kinds: []uint16{1, 4, 8, 16}})
|
||||
pk3 := nostr.GetPublicKey(sk3)
|
||||
filters = append(filters, nostr.Filter{Authors: []nostr.PubKey{pk3, nostr.Generate().Public()}})
|
||||
filters = append(filters, nostr.Filter{Authors: []nostr.PubKey{pk3, nostr.Generate().Public()}, Kinds: []uint16{3, 4}})
|
||||
filters = append(filters, nostr.Filter{})
|
||||
filters = append(filters, nostr.Filter{Limit: 20})
|
||||
filters = append(filters, nostr.Filter{Kinds: []int{8, 9}, Tags: nostr.TagMap{"p": []string{pk3}}})
|
||||
pk4, _ := nostr.GetPublicKey(sk4)
|
||||
filters = append(filters, nostr.Filter{Kinds: []int{8, 9}, Tags: nostr.TagMap{"p": []string{pk3, pk4}}})
|
||||
filters = append(filters, nostr.Filter{Kinds: []int{8, 9}, Tags: nostr.TagMap{"p": []string{pk3, pk4}}})
|
||||
filters = append(filters, nostr.Filter{Kinds: []uint16{8, 9}, Tags: nostr.TagMap{"p": []string{pk3.Hex()}}})
|
||||
pk4 := nostr.GetPublicKey(sk4)
|
||||
filters = append(filters, nostr.Filter{Kinds: []uint16{8, 9}, Tags: nostr.TagMap{"p": []string{pk3.Hex(), pk4.Hex()}}})
|
||||
filters = append(filters, nostr.Filter{Kinds: []uint16{8, 9}, Tags: nostr.TagMap{"p": []string{pk3.Hex(), pk4.Hex()}}})
|
||||
eTags := make([]string, 20)
|
||||
for i := 0; i < 20; i++ {
|
||||
eTag := make([]byte, 32)
|
||||
binary.BigEndian.PutUint16(eTag, uint16(i))
|
||||
eTags[i] = hex.EncodeToString(eTag)
|
||||
}
|
||||
filters = append(filters, nostr.Filter{Kinds: []int{9}, Tags: nostr.TagMap{"e": eTags}})
|
||||
filters = append(filters, nostr.Filter{Kinds: []int{5}, Tags: nostr.TagMap{"e": eTags, "t": []string{"t5"}}})
|
||||
filters = append(filters, nostr.Filter{Kinds: []uint16{9}, Tags: nostr.TagMap{"e": eTags}})
|
||||
filters = append(filters, nostr.Filter{Kinds: []uint16{5}, Tags: nostr.TagMap{"e": eTags, "t": []string{"t5"}}})
|
||||
filters = append(filters, nostr.Filter{Tags: nostr.TagMap{"e": eTags}})
|
||||
filters = append(filters, nostr.Filter{Tags: nostr.TagMap{"e": eTags}, Limit: 50})
|
||||
|
||||
@@ -97,17 +88,17 @@ func runBenchmarkOn(b *testing.B, db eventstore.Store) {
|
||||
for q, filter := range filters {
|
||||
b.Run(fmt.Sprintf("q-%d", q), func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, _ = db.QueryEvents(ctx, filter)
|
||||
_ = db.QueryEvents(filter)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
b.Run("insert", func(b *testing.B) {
|
||||
evt := &nostr.Event{Kind: 788, CreatedAt: nostr.Now(), Content: "blergh", Tags: nostr.Tags{{"t", "spam"}}}
|
||||
evt := nostr.Event{Kind: 788, CreatedAt: nostr.Now(), Content: "blergh", Tags: nostr.Tags{{"t", "spam"}}}
|
||||
evt.Sign(sk4)
|
||||
for i := 0; i < b.N; i++ {
|
||||
db.SaveEvent(ctx, evt)
|
||||
db.SaveEvent(evt)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user