-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(context): avoid unnecessary copies in KVStore, TransientStore an…
…d CacheContext methods (#14354) Co-authored-by: testinginprod <[email protected]> Co-authored-by: Aleksandr Bezobchuk <[email protected]>
- Loading branch information
1 parent
de6ef1e
commit c918b14
Showing
3 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/store/types" | ||
"github.com/cosmos/cosmos-sdk/testutil" | ||
) | ||
|
||
func BenchmarkContext_KVStore(b *testing.B) { | ||
key := types.NewKVStoreKey(b.Name() + "_TestCacheContext") | ||
|
||
ctx := testutil.DefaultContext(key, types.NewTransientStoreKey("transient_"+b.Name())) | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_ = ctx.KVStore(key) | ||
} | ||
} | ||
|
||
func BenchmarkContext_TransientStore(b *testing.B) { | ||
key := types.NewKVStoreKey(b.Name() + "_TestCacheContext") | ||
|
||
ctx := testutil.DefaultContext(key, types.NewTransientStoreKey("transient_"+b.Name())) | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_ = ctx.TransientStore(key) | ||
} | ||
} | ||
|
||
func BenchmarkContext_CacheContext(b *testing.B) { | ||
key := types.NewKVStoreKey(b.Name() + "_TestCacheContext") | ||
|
||
ctx := testutil.DefaultContext(key, types.NewTransientStoreKey("transient_"+b.Name())) | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_, _ = ctx.CacheContext() | ||
} | ||
} |