Skip to content

Commit

Permalink
tests(share/eds): add store basic benchmarks (#2407)
Browse files Browse the repository at this point in the history
## Overview

Implements basic benchmarks for eds store implementation.
  • Loading branch information
walldiss committed Jun 29, 2023
1 parent 4d98694 commit 9ee5080
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions share/eds/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,49 @@ func Test_CachedAccessor(t *testing.T) {
assert.Equal(t, firstBlock, secondBlock)
}

func BenchmarkStore(b *testing.B) {
ctx, cancel := context.WithCancel(context.Background())
b.Cleanup(cancel)

tmpDir := b.TempDir()
ds := ds_sync.MutexWrap(datastore.NewMapDatastore())
edsStore, err := NewStore(tmpDir, ds)
require.NoError(b, err)
err = edsStore.Start(ctx)
require.NoError(b, err)

// BenchmarkStore/bench_put_128-10 10 3231859283 ns/op (~3sec)
b.Run("bench put 128", func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
// pause the timer for initializing test data
b.StopTimer()
eds := edstest.RandEDS(b, 128)
dah := da.NewDataAvailabilityHeader(eds)
b.StartTimer()

err = edsStore.Put(ctx, dah.Hash(), eds)
require.NoError(b, err)
}
})

// BenchmarkStore/bench_read_128-10 14 78970661 ns/op (~70ms)
b.Run("bench read 128", func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
// pause the timer for initializing test data
b.StopTimer()
eds := edstest.RandEDS(b, 128)
dah := da.NewDataAvailabilityHeader(eds)
_ = edsStore.Put(ctx, dah.Hash(), eds)
b.StartTimer()

_, err := edsStore.Get(ctx, dah.Hash())
require.NoError(b, err)
}
})
}

func newStore(t *testing.T) (*Store, error) {
t.Helper()

Expand Down

0 comments on commit 9ee5080

Please sign in to comment.