Skip to content

Commit

Permalink
Report put/get metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Aug 25, 2020
1 parent e6282fa commit 8bed850
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions amt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,34 @@ func init() {
}

type mockBlocks struct {
data map[cid.Cid]block.Block
data map[cid.Cid]block.Block
getCount, putCount int
}

func newMockBlocks() *mockBlocks {
return &mockBlocks{make(map[cid.Cid]block.Block)}
return &mockBlocks{make(map[cid.Cid]block.Block), 0, 0}
}

func (mb *mockBlocks) Get(c cid.Cid) (block.Block, error) {
d, ok := mb.data[c]
mb.getCount++
if ok {
return d, nil
}
return nil, fmt.Errorf("Not Found")
}

func (mb *mockBlocks) Put(b block.Block) error {
mb.putCount++
mb.data[b.Cid()] = b
return nil
}

func (mb *mockBlocks) report(b *testing.B) {
b.ReportMetric(float64(mb.getCount)/float64(b.N), "gets/op")
b.ReportMetric(float64(mb.putCount)/float64(b.N), "puts/op")
}

func TestBasicSetGet(t *testing.T) {
bs := cbor.NewCborStore(newMockBlocks())
ctx := context.Background()
Expand Down Expand Up @@ -578,7 +586,10 @@ func TestDeleteReduceHeight(t *testing.T) {
}

func BenchmarkAMTInsertBulk(b *testing.B) {
bs := cbor.NewCborStore(newMockBlocks())
mock := newMockBlocks()
defer mock.report(b)

bs := cbor.NewCborStore(mock)
ctx := context.Background()

for i := 0; i < b.N; i++ {
Expand Down Expand Up @@ -615,7 +626,10 @@ func BenchmarkAMTInsertBulk(b *testing.B) {
}

func BenchmarkAMTLoadAndInsert(b *testing.B) {
bs := cbor.NewCborStore(newMockBlocks())
mock := newMockBlocks()
defer mock.report(b)

bs := cbor.NewCborStore(mock)
ctx := context.Background()
a := NewAMT(bs)

Expand Down

0 comments on commit 8bed850

Please sign in to comment.