11package block
22
33import (
4+ "fmt"
45 "os"
56 "testing"
67
@@ -30,7 +31,7 @@ func BenchmarkDirtyTracking(b *testing.B) {
3031 b .ReportAllocs ()
3132 b .ResetTimer ()
3233
33- for i := 0 ; i < b .N ; i ++ {
34+ for i := range b .N {
3435 // Simulate marking a block as cached
3536 off := int64 (i % 262144 ) * blockSize
3637 cache .setIsCached (off , blockSize )
@@ -39,14 +40,14 @@ func BenchmarkDirtyTracking(b *testing.B) {
3940
4041 b .Run ("IsCached_Hit" , func (b * testing.B ) {
4142 // Pre-populate some blocks as cached
42- for i := int64 (0 ); i < 1000 ; i ++ {
43+ for i := range int64 (1000 ) {
4344 cache .setIsCached (i * blockSize , blockSize )
4445 }
4546
4647 b .ReportAllocs ()
4748 b .ResetTimer ()
4849
49- for i := 0 ; i < b .N ; i ++ {
50+ for i := range b .N {
5051 off := int64 (i % 1000 ) * blockSize
5152 cache .isCached (off , blockSize )
5253 }
@@ -56,7 +57,7 @@ func BenchmarkDirtyTracking(b *testing.B) {
5657 b .ReportAllocs ()
5758 b .ResetTimer ()
5859
59- for i := 0 ; i < b .N ; i ++ {
60+ for i := range b .N {
6061 // Check blocks that are definitely not cached (high offsets)
6162 off := int64 (100000 + i % 100000 ) * blockSize
6263 cache .isCached (off , blockSize )
@@ -67,7 +68,7 @@ func BenchmarkDirtyTracking(b *testing.B) {
6768 b .ReportAllocs ()
6869 b .ResetTimer ()
6970
70- for i := 0 ; i < b .N ; i ++ {
71+ for i := range b .N {
7172 off := int64 (i % 262144 ) * blockSize
7273 cache .WriteAt (data , off )
7374 }
@@ -80,7 +81,7 @@ func BenchmarkDirtyTracking(b *testing.B) {
8081 b .ReportAllocs ()
8182 b .ResetTimer ()
8283
83- for i := 0 ; i < b .N ; i ++ {
84+ for i := range b .N {
8485 off := int64 (i % 65536 ) * blockSize * 4
8586 cache .WriteAt (multiBlockData , off )
8687 }
@@ -104,15 +105,15 @@ func BenchmarkDirtySortedKeys(b *testing.B) {
104105 defer cache .Close ()
105106
106107 // Mark 10% of blocks as dirty (26214 blocks)
107- for i := int64 (0 ); i < 26214 ; i ++ {
108+ for i := range int64 (26214 ) {
108109 cache .setIsCached (i * blockSize , blockSize )
109110 }
110111
111112 b .Run ("DirtySortedKeys_10pct" , func (b * testing.B ) {
112113 b .ReportAllocs ()
113114 b .ResetTimer ()
114115
115- for i := 0 ; i < b .N ; i ++ {
116+ for range b .N {
116117 keys := cache .dirtySortedKeys ()
117118 _ = keys
118119 }
@@ -138,7 +139,7 @@ func BenchmarkCacheCreation(b *testing.B) {
138139 b .ReportAllocs ()
139140 b .ResetTimer ()
140141
141- for i := 0 ; i < b .N ; i ++ {
142+ for range b .N {
142143 tmpFile := b .TempDir () + "/bench_cache"
143144 cache , err := NewCache (size , blockSize , tmpFile , false )
144145 if err != nil {
@@ -160,10 +161,10 @@ func formatSize(bytes int64) string {
160161
161162 switch {
162163 case bytes >= GB :
163- return string ( rune ( '0' + bytes / GB )) + "GB"
164+ return fmt . Sprintf ( "%dGB" , bytes / GB )
164165 case bytes >= MB :
165- return string ( rune ( '0' + bytes / MB )) + "MB"
166+ return fmt . Sprintf ( "%dMB" , bytes / MB )
166167 default :
167- return string ( rune ( '0' + bytes / KB )) + "KB"
168+ return fmt . Sprintf ( "%dKB" , bytes / KB )
168169 }
169170}
0 commit comments