Skip to content

Commit 3d4d09c

Browse files
committed
Add a benchmark for DeleteExpired()
1 parent 0ba3e00 commit 3d4d09c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cache_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,3 +1591,19 @@ func BenchmarkRWMutexMapSetDeleteSingleLock(b *testing.B) {
15911591
mu.Unlock()
15921592
}
15931593
}
1594+
1595+
func BenchmarkDeleteExpired(b *testing.B) {
1596+
b.StopTimer()
1597+
tc := New(1, 0)
1598+
tc.mu.Lock()
1599+
for i := 0; i < b.N; i++ {
1600+
tc.set(strconv.Itoa(i), "bar", DefaultExpiration)
1601+
}
1602+
tc.mu.Unlock()
1603+
time.Sleep(100)
1604+
if _, found := tc.Get("0"); found {
1605+
b.Fatal("0 found")
1606+
}
1607+
b.StartTimer()
1608+
tc.DeleteExpired()
1609+
}

0 commit comments

Comments
 (0)