From 3d4d09ca0bf8df26cd38a90bdc7968177f976464 Mon Sep 17 00:00:00 2001 From: Patrick Mylund Nielsen Date: Sat, 28 Nov 2015 14:35:38 -0500 Subject: [PATCH] Add a benchmark for DeleteExpired() --- cache_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cache_test.go b/cache_test.go index 13f17ae..cc6b511 100644 --- a/cache_test.go +++ b/cache_test.go @@ -1591,3 +1591,19 @@ func BenchmarkRWMutexMapSetDeleteSingleLock(b *testing.B) { mu.Unlock() } } + +func BenchmarkDeleteExpired(b *testing.B) { + b.StopTimer() + tc := New(1, 0) + tc.mu.Lock() + for i := 0; i < b.N; i++ { + tc.set(strconv.Itoa(i), "bar", DefaultExpiration) + } + tc.mu.Unlock() + time.Sleep(100) + if _, found := tc.Get("0"); found { + b.Fatal("0 found") + } + b.StartTimer() + tc.DeleteExpired() +}