forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR cosmos#4265: CacheKVStore keep sorted items
- Loading branch information
1 parent
d8bd7bc
commit dfef88d
Showing
5 changed files
with
133 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#2286 Improve performance of CacheKVStore iterator. |
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,46 @@ | ||
package cachekv_test | ||
|
||
import ( | ||
"crypto/rand" | ||
"sort" | ||
"testing" | ||
|
||
dbm "github.com/tendermint/tendermint/libs/db" | ||
|
||
"github.com/cosmos/cosmos-sdk/store/cachekv" | ||
"github.com/cosmos/cosmos-sdk/store/dbadapter" | ||
) | ||
|
||
func benchmarkCacheKVStoreIterator(numKVs int, b *testing.B) { | ||
mem := dbadapter.Store{DB: dbm.NewMemDB()} | ||
cstore := cachekv.NewStore(mem) | ||
keys := make([]string, numKVs, numKVs) | ||
|
||
for i := 0; i < numKVs; i++ { | ||
key := make([]byte, 32) | ||
value := make([]byte, 32) | ||
|
||
_, _ = rand.Read(key) | ||
_, _ = rand.Read(value) | ||
|
||
keys[i] = string(key) | ||
cstore.Set(key, value) | ||
} | ||
|
||
sort.Strings(keys) | ||
|
||
for n := 0; n < b.N; n++ { | ||
iter := cstore.Iterator([]byte(keys[0]), []byte(keys[numKVs-1])) | ||
|
||
for _ = iter.Key(); iter.Valid(); iter.Next() { | ||
} | ||
|
||
iter.Close() | ||
} | ||
} | ||
|
||
func BenchmarkCacheKVStoreIterator500(b *testing.B) { benchmarkCacheKVStoreIterator(500, b) } | ||
func BenchmarkCacheKVStoreIterator1000(b *testing.B) { benchmarkCacheKVStoreIterator(1000, b) } | ||
func BenchmarkCacheKVStoreIterator10000(b *testing.B) { benchmarkCacheKVStoreIterator(10000, b) } | ||
func BenchmarkCacheKVStoreIterator50000(b *testing.B) { benchmarkCacheKVStoreIterator(50000, b) } | ||
func BenchmarkCacheKVStoreIterator100000(b *testing.B) { benchmarkCacheKVStoreIterator(100000, b) } |
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