Skip to content

Commit

Permalink
chore: Update ouroboros_test.go to include benchmark for `GetEvents…
Browse files Browse the repository at this point in the history
…ByFastMeta`
  • Loading branch information
i5heu committed May 18, 2024
1 parent 51afe3a commit 281a045
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
60 changes: 60 additions & 0 deletions ouroboros_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,3 +1051,63 @@ func Benchmark_Index_GetEventHashesByFastMetaParameter(b *testing.B) {
}
})
}

func Benchmark_Index_GetEventsByFastMeta(b *testing.B) {
ou, evhs := setupDBWithData(b, setupDBConfig{
totalEvents: 1,
})

rootEvHash := evhs[0]

savedEvHashWithFastMeta := make(map[types.Hash]types.FastMeta)

for i := 0; i < 1000; i++ {
fm := types.FastMeta{
types.FastMetaParameter([]byte("test2")),
types.FastMetaParameter([]byte("test3")),
}

if i%2 == 0 {
fm = append(fm, types.FastMetaParameter([]byte("test4")))
} else {
fm = append(fm, types.FastMetaParameter([]byte("test5")))
}

insertEv, err := ou.DB.CreateNewEvent(storage.EventOptions{
ParentEvent: rootEvHash,
FastMeta: fm,
})
if err != nil {
b.Fatalf("CreateNewEvent failed with error: %v", err)
}

savedEvHashWithFastMeta[insertEv.EventHash] = fm
}

// Rebuild the index
resultEv, err := ou.DB.GetAllEvents()
if err != nil {
b.Fatalf("GetAllEvents failed with error: %v", err)
}
_, err = ou.Index.RebuildFastMeta(resultEv)
if err != nil {
b.Fatalf("RebuildFastMeta failed with error: %v", err)
}

b.ResetTimer()
b.Run("GetEventsByFastMeta", func(b *testing.B) {
for i := 0; i < b.N; i++ {
fm := types.FastMeta{
types.FastMetaParameter([]byte("test3")),
types.FastMetaParameter([]byte("test4")),
}
hash, err := ou.Index.GetEventsByFastMeta(fm)
if err != nil {
b.Errorf("GetEventsByFastMeta failed with error: %v", err)
}
if len(hash) == 0 {
b.Errorf("GetEventsByFastMeta failed, expected non-zero count, got %d", len(hash))
}
}
})
}
2 changes: 0 additions & 2 deletions pkg/index/FastMeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ func (i *Index) GetEventsByFastMeta(fm types.FastMeta) ([]types.Event, error) {

evHashes := i.GetEventHashesByFastMeta(fm)

fmt.Println("evHashes", evHashes)

events := make([]types.Event, 0)
for _, eventHash := range evHashes {
event, err := i.s.GetEvent(eventHash)
Expand Down

0 comments on commit 281a045

Please sign in to comment.