Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stf/branch): simplify merged iterator #22131

Merged
merged 18 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions server/v2/stf/branch/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package branch

import (
"testing"

"cosmossdk.io/core/store"
coretesting "cosmossdk.io/core/testing"
)

func Benchmark_CacheStack1_Set(b *testing.B) {
bs := makeBranchStack(b, 1)
b.ResetTimer()
b.ReportAllocs()
// test sets
for i := 0; i < b.N; i++ {
err := bs.Set([]byte{0}, []byte{0})
if err != nil {
b.Fatal(err)
}
}
}

func Benchmark_CacheStack10_Set(b *testing.B) {
bs := makeBranchStack(b, 10)
b.ResetTimer()
b.ReportAllocs()
// test sets
for i := 0; i < b.N; i++ {
err := bs.Set([]byte{0}, []byte{0})
if err != nil {
b.Fatal(err)
}
}
}

func Benchmark_CacheStack100_Set(b *testing.B) {
bs := makeBranchStack(b, 100)
b.ResetTimer()
b.ReportAllocs()
// test sets
for i := 0; i < b.N; i++ {
err := bs.Set([]byte{0}, []byte{0})
if err != nil {
b.Fatal(err)
}
}
}
testinginprod marked this conversation as resolved.
Show resolved Hide resolved
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved

func Benchmark_CacheStack1_Get(b *testing.B) {
bs := makeBranchStack(b, 1)
b.ResetTimer()
b.ReportAllocs()
// test sets
for i := 0; i < b.N; i++ {
_, err := bs.Get([]byte{0})
if err != nil {
b.Fatal(err)
}
}
}

func Benchmark_CacheStack10_Get(b *testing.B) {
bs := makeBranchStack(b, 10)
b.ResetTimer()
b.ReportAllocs()
// test sets
for i := 0; i < b.N; i++ {
_, err := bs.Get([]byte{0})
if err != nil {
b.Fatal(err)
}
}
}

func Benchmark_CacheStack100_Get(b *testing.B) {
bs := makeBranchStack(b, 100)
b.ResetTimer()
b.ReportAllocs()
// test sets
for i := 0; i < b.N; i++ {
_, err := bs.Get([]byte{0})
if err != nil {
b.Fatal(err)
}
}
}
testinginprod marked this conversation as resolved.
Show resolved Hide resolved

func Benchmark_CacheStack1_Iterate(b *testing.B) {
bs := makeBranchStack(b, 1)
var keySink, valueSink any

b.ResetTimer()
b.ReportAllocs()
// test sets
for i := 0; i < b.N; i++ {
iter, err := bs.Iterator([]byte{0}, []byte{0})
if err != nil {
b.Fatal(err)
}
for iter.Valid() {
iter.Next()
keySink = iter.Key()
valueSink = iter.Value()
}
}

_ = keySink
_ = valueSink
}

func Benchmark_CacheStack10_Iterate(b *testing.B) {
bs := makeBranchStack(b, 10)
var keySink, valueSink any

b.ResetTimer()
b.ReportAllocs()
// test sets
for i := 0; i < b.N; i++ {
iter, err := bs.Iterator([]byte{0}, []byte{0})
if err != nil {
b.Fatal(err)
}
for iter.Valid() {
iter.Next()
keySink = iter.Key()
valueSink = iter.Value()
}
}

_ = keySink
_ = valueSink
}

func Benchmark_CacheStack100_Iterate(b *testing.B) {
bs := makeBranchStack(b, 100)
var keySink, valueSink any

b.ResetTimer()
b.ReportAllocs()
// test sets
for i := 0; i < b.N; i++ {
iter, err := bs.Iterator([]byte{0}, []byte{0})
if err != nil {
b.Fatal(err)
}
for iter.Valid() {
iter.Next()
keySink = iter.Key()
valueSink = iter.Value()
}
}

_ = keySink
_ = valueSink
}
testinginprod marked this conversation as resolved.
Show resolved Hide resolved

func makeBranchStack(b *testing.B, stackSize int) Store[store.KVStore] {
const elems = 10
parent := coretesting.NewMemKV()
branch := NewStore[store.KVStore](parent)
for i := 1; i < stackSize; i++ {
branch = NewStore[store.KVStore](branch)
for j := 0; j < elems; j++ {
key, value := []byte{byte(j)}, []byte{byte(j)}
err := branch.Set(key, value)
if err != nil {
b.Fatal(err)
}
}
}
return branch
}
testinginprod marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading