Skip to content

Commit 3f444db

Browse files
Thomas StrombergThomas Stromberg
authored andcommitted
fix unfair freecache benchmark config
1 parent b49e313 commit 3f444db

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

benchmarks/benchmark_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,21 @@ func TestBenchmarkSuite(t *testing.T) {
4444
// =============================================================================
4545

4646
const (
47-
hitRateKeySpace = 500000
48-
hitRateWorkload = 750000
47+
hitRateKeySpace = 1000000
48+
hitRateWorkload = 1000000
4949
hitRateAlpha = 0.99
5050
)
5151

5252
func runHitRateBenchmark() {
5353
fmt.Println()
54-
fmt.Println("### Hit Rate (Zipf α=0.99, 750K ops)")
54+
fmt.Println("### Hit Rate (Zipf α=0.99, 1M ops, 1M keyspace)")
5555
fmt.Println()
56-
fmt.Println("| Cache | Size=0.1% | Size=1% | Size=10% |")
56+
fmt.Println("| Cache | Size=2.5% | Size=5% | Size=10% |")
5757
fmt.Println("|------------|-----------|---------|----------|")
5858

5959
workload := generateWorkload(hitRateWorkload, hitRateKeySpace, hitRateAlpha, 42)
60-
cacheSizes := []int{500, 5000, 50000}
60+
// Use sizes >= 25K so freecache's 512KB minimum doesn't give unfair advantage
61+
cacheSizes := []int{25000, 50000, 100000}
6162

6263
caches := []struct {
6364
name string
@@ -165,10 +166,10 @@ func hitRateTinyLFU(workload []int, cacheSize int) float64 {
165166
}
166167

167168
func hitRateFreecache(workload []int, cacheSize int) float64 {
168-
// freecache uses bytes, estimate ~64 bytes per entry
169-
cacheBytes := cacheSize * 64
169+
// freecache uses bytes; estimate ~24 bytes per entry (key + value + overhead)
170+
cacheBytes := cacheSize * 24
170171
if cacheBytes < 512*1024 {
171-
cacheBytes = 512 * 1024 // minimum 512KB
172+
cacheBytes = 512 * 1024 // freecache minimum
172173
}
173174
cache := freecache.NewCache(cacheBytes)
174175
var hits int

0 commit comments

Comments
 (0)