Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func BenchmarkEncodeBlockBuffer(b *testing.B) {

b.Run("Optimized", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for b.Loop() {
buf := make([]byte, 1+32+32+len(encodedPayload))
buf[0] = version
copy(buf[1:], parentRoot[:])
Expand All @@ -47,7 +47,7 @@ func BenchmarkEncodeBlockBuffer(b *testing.B) {

b.Run("Old", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for b.Loop() {
buf := append([]byte{version}, append(append(parentRoot[:], requestsHash[:]...), encodedPayload...)...)
_ = buf
}
Expand Down
4 changes: 2 additions & 2 deletions cl/sentinel/handlers/light_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func BenchmarkLightClientPrefixConstruction(b *testing.B) {

b.Run("Optimized", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for b.Loop() {
var prefix [5]byte
prefix[0] = SuccessfulResponsePrefix
copy(prefix[1:], forkDigest[:])
Expand All @@ -419,7 +419,7 @@ func BenchmarkLightClientPrefixConstruction(b *testing.B) {

b.Run("Old", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for b.Loop() {
prefix := append([]byte{SuccessfulResponsePrefix}, forkDigest[:]...)
_ = prefix
}
Expand Down
2 changes: 0 additions & 2 deletions common/crypto/blake2b/blake2b_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ func benchmarkSum(b *testing.B, size int, sse4, avx, avx2 bool) {

data := make([]byte, size)
b.SetBytes(int64(size))
b.ResetTimer()
for b.Loop() {
Sum512(data)
}
Expand All @@ -332,7 +331,6 @@ func benchmarkWrite(b *testing.B, size int, sse4, avx, avx2 bool) {
data := make([]byte, size)
h, _ := New512(nil)
b.SetBytes(int64(size))
b.ResetTimer()
for b.Loop() {
h.Write(data)
}
Expand Down
4 changes: 2 additions & 2 deletions common/lru/basiclru_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func BenchmarkLRU(b *testing.B) {

b.Run("Add/BasicLRU", func(b *testing.B) {
cache := NewBasicLRU[int, int](capacity)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
cache.Add(i, i)
}
})
Expand All @@ -221,7 +221,7 @@ func BenchmarkLRU(b *testing.B) {
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
k := keys[indexes[i%len(indexes)]]
v, ok := cache.Get(k)
if ok {
Expand Down
16 changes: 0 additions & 16 deletions common/maphash/maphash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ func BenchmarkMapSet(b *testing.B) {
m := NewMap[int]()
key := []byte("benchmark-key")

b.ResetTimer()
for b.Loop() {
m.Set(key, 123)
}
Expand All @@ -301,7 +300,6 @@ func BenchmarkMapGet(b *testing.B) {
key := []byte("benchmark-key")
m.Set(key, 123)

b.ResetTimer()
for b.Loop() {
m.Get(key)
}
Expand Down Expand Up @@ -503,7 +501,6 @@ func BenchmarkLRUSet(b *testing.B) {
l, _ := NewLRU[int](10000)
key := []byte("benchmark-key")

b.ResetTimer()
for b.Loop() {
l.Set(key, 123)
}
Expand All @@ -515,7 +512,6 @@ func BenchmarkLRUGet(b *testing.B) {
key := []byte("benchmark-key")
l.Set(key, 123)

b.ResetTimer()
for b.Loop() {
l.Get(key)
}
Expand Down Expand Up @@ -553,7 +549,6 @@ func BenchmarkMaphashMapSet(b *testing.B) {
m := NewMap[int]()
key := []byte("benchmark-key-that-is-48-bytes-long-like-pubkey!")

b.ResetTimer()
for b.Loop() {
m.Set(key, 123)
}
Expand All @@ -563,7 +558,6 @@ func BenchmarkStringMapSet(b *testing.B) {
m := NewStringMap[int]()
key := []byte("benchmark-key-that-is-48-bytes-long-like-pubkey!")

b.ResetTimer()
for b.Loop() {
m.Set(key, 123)
}
Expand All @@ -577,7 +571,6 @@ func BenchmarkMaphashMapGet(b *testing.B) {
key := []byte("benchmark-key-that-is-48-bytes-long-like-pubkey!")
m.Set(key, 123)

b.ResetTimer()
for b.Loop() {
m.Get(key)
}
Expand All @@ -588,7 +581,6 @@ func BenchmarkStringMapGet(b *testing.B) {
key := []byte("benchmark-key-that-is-48-bytes-long-like-pubkey!")
m.Set(key, 123)

b.ResetTimer()
for b.Loop() {
m.Get(key)
}
Expand All @@ -609,7 +601,6 @@ func BenchmarkMaphashMapSetManyKeys(b *testing.B) {
keys[i][3] = byte(i)
}

b.ResetTimer()
i := 0
for b.Loop() {
m := NewMap[int]()
Expand All @@ -631,7 +622,6 @@ func BenchmarkStringMapSetManyKeys(b *testing.B) {
keys[i][3] = byte(i)
}

b.ResetTimer()
i := 0
for b.Loop() {
m := NewStringMap[int]()
Expand All @@ -653,7 +643,6 @@ func BenchmarkUniqueHandleMapSetManyKeys(b *testing.B) {
keys[i][3] = byte(i)
}

b.ResetTimer()
i := 0
for b.Loop() {
m := NewUniqueHandleMap[int]()
Expand Down Expand Up @@ -681,7 +670,6 @@ func BenchmarkMaphashMapGetManyKeys(b *testing.B) {
m.Set(keys[i], i)
}

b.ResetTimer()
i := 0
for b.Loop() {
m.Get(keys[i%len(keys)])
Expand All @@ -703,7 +691,6 @@ func BenchmarkStringMapGetManyKeys(b *testing.B) {
m.Set(keys[i], i)
}

b.ResetTimer()
i := 0
for b.Loop() {
m.Get(keys[i%len(keys)])
Expand Down Expand Up @@ -769,7 +756,6 @@ func BenchmarkUniqueHandleMapSet(b *testing.B) {
m := NewUniqueHandleMap[int]()
key := []byte("benchmark-key-that-is-48-bytes-long-like-pubkey!")

b.ResetTimer()
for b.Loop() {
m.Set(key, 123)
}
Expand All @@ -780,7 +766,6 @@ func BenchmarkUniqueHandleMapGet(b *testing.B) {
key := []byte("benchmark-key-that-is-48-bytes-long-like-pubkey!")
m.Set(key, 123)

b.ResetTimer()
for b.Loop() {
m.Get(key)
}
Expand All @@ -800,7 +785,6 @@ func BenchmarkUniqueHandleMapGetManyKeys(b *testing.B) {
m.Set(keys[i], i)
}

b.ResetTimer()
i := 0
for b.Loop() {
m.Get(keys[i%len(keys)])
Expand Down
16 changes: 6 additions & 10 deletions db/kv/mdbx/kv_mdbx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,6 @@ func BenchmarkDB_BeginRO(b *testing.B) {
_db := BaseCaseDBForBenchmark(b)
db := _db.(*MdbxKV)

b.ResetTimer()
for b.Loop() {
tx, _ := db.BeginRo(context.Background())
tx.Rollback()
Expand All @@ -1010,7 +1009,6 @@ func BenchmarkDB_Get(b *testing.B) {
// Ensure data is correct.
if err := db.View(context.Background(), func(tx kv.Tx) error {
key := u64tob(uint64(1))
b.ResetTimer()
for b.Loop() {
v, err := tx.GetOne(table, key)
if err != nil {
Expand All @@ -1031,13 +1029,12 @@ func BenchmarkDB_Put(b *testing.B) {
table := "Table"
db := _db.(*MdbxKV)

// Ensure data is correct.
keys := make([][]byte, b.N)
for i := 1; i <= b.N; i++ {
const keyCount = 10000
keys := make([][]byte, keyCount)
for i := 1; i <= keyCount; i++ {
keys[i-1] = u64tob(uint64(i))
}

b.ResetTimer()
if err := db.Update(context.Background(), func(tx kv.RwTx) error {
var idx int
for b.Loop() {
Expand Down Expand Up @@ -1082,8 +1079,9 @@ func BenchmarkDB_Delete(b *testing.B) {
table := "Table"
db := _db.(*MdbxKV)

keys := make([][]byte, b.N)
for i := 1; i <= b.N; i++ {
const keyCount = 10000
keys := make([][]byte, keyCount)
for i := 1; i <= keyCount; i++ {
keys[i-1] = u64tob(uint64(i))
}

Expand All @@ -1099,8 +1097,6 @@ func BenchmarkDB_Delete(b *testing.B) {
b.Fatal(err)
}

// Ensure data is correct.
b.ResetTimer()
if err := db.Update(context.Background(), func(tx kv.RwTx) error {
var idx int
for b.Loop() {
Expand Down
3 changes: 1 addition & 2 deletions db/recsplit/multiencseq/sequence_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ func BenchmarkBuilder(b *testing.B) {
vals[i] = baseNum + uint64(i)*2
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
sb := NewBuilder(baseNum, n, vals[n-1])
for _, v := range vals {
sb.AddOffset(v)
Expand Down
3 changes: 1 addition & 2 deletions db/recsplit/multiencseq/sequence_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ func BenchmarkMerge(b *testing.B) {

var s1, s2 SequenceReader
var merged SequenceBuilder
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
s1.Reset(baseNum, raw1)
s2.Reset(baseNum, raw2)
if err := merged.Merge(&s1, &s2, baseNum); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions db/recsplit/recsplit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ func BenchmarkFindSplit(b *testing.B) {
salt := uint64(0x6453cec3f7376937) // startSeed[1]
count := make([]uint16, secondaryAggrBound)

b.ResetTimer()
for b.Loop() {
for i := range buckets {
findSplit(buckets[i][:], salt, fanout, unit, count)
Expand All @@ -325,7 +324,6 @@ func BenchmarkFindBijection(b *testing.B) {
}
salt := uint64(0x106393c187cae2a) // startSeed[0]

b.ResetTimer()
for b.Loop() {
for i := range buckets {
findBijection(buckets[i][:], salt)
Expand Down Expand Up @@ -393,7 +391,7 @@ func BenchmarkAddKeyAndBuild(b *testing.B) {
name = "enums"
}
b.Run(name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
b.StopTimer()
indexFile := filepath.Join(tmpDir, fmt.Sprintf("index_full_%s_%d", name, i))
rs, err := NewRecSplit(RecSplitArgs{
Expand Down
3 changes: 1 addition & 2 deletions db/version/file_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,7 @@ func BenchmarkMatchVersionedFile(b *testing.B) {
)
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_, _, _, _ = MatchVersionedFile("*-accounts.0-1.kvi", dirEntries, "/tmp")
}
}
3 changes: 1 addition & 2 deletions execution/commitment/keys_nibbles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ func BenchmarkKeyToHexNibbleHash(b *testing.B) {
for i := range key {
key[i] = byte(i)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
KeyToHexNibbleHash(key)
}
}
18 changes: 9 additions & 9 deletions execution/commitment/warmup_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func BenchmarkWarmupCache_Branch(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
key := keys[i%len(keys)]
cache.GetBranch(key)
}
Expand All @@ -231,15 +231,15 @@ func BenchmarkWarmupCache_Branch(b *testing.B) {
// BenchmarkWarmupCache_Branch_Put benchmarks Put operations
func BenchmarkWarmupCache_Branch_Put(b *testing.B) {
cache := NewWarmupCache()
keys := generateTestKeys(b.N, 52)
const keyCount = 10000
keys := generateTestKeys(keyCount, 52)
data := make([]byte, 100)
rand.Read(data)

b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
cache.PutBranch(keys[i], data)
for i := 0; b.Loop(); i++ {
cache.PutBranch(keys[i%keyCount], data)
}
}

Expand All @@ -256,7 +256,7 @@ func BenchmarkWarmupCache_Account(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
key := keys[i%len(keys)]
cache.GetAccount(key)
}
Expand All @@ -275,7 +275,7 @@ func BenchmarkWarmupCache_Storage(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
key := keys[i%len(keys)]
cache.GetStorage(key)
}
Expand Down Expand Up @@ -304,7 +304,7 @@ func BenchmarkWarmupCache_Mixed(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
switch i % 3 {
case 0:
cache.GetAccount(accountKeys[i%len(accountKeys)])
Expand All @@ -329,7 +329,7 @@ func BenchmarkComparison_Map_100k(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
cache.GetStorage(keys[i%len(keys)])
}
}
Loading
Loading