From be7efe5287392ae2526d420a8e74bbf55f2aa26f Mon Sep 17 00:00:00 2001 From: Giuseppe Date: Tue, 1 Dec 2015 22:02:17 +0100 Subject: [PATCH 1/3] modified test --- cache_test.go | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/cache_test.go b/cache_test.go index 1456c58..4333af4 100644 --- a/cache_test.go +++ b/cache_test.go @@ -1650,15 +1650,41 @@ func BenchmarkDeleteExpiredLoop(b *testing.B) { func BenchmarkLargeCache(b *testing.B) { b.StopTimer() - tc := New(100 * time.Millisecond, 1 * time.Millisecond) - //tc.mu.Lock() - for i := 0; i < 1000000; i++ { - tc.Set(strconv.Itoa(i), "bar", DefaultExpiration) - } - //tc.mu.Unlock() - tc.DeleteExpired() + tc := New(100*time.Millisecond, 5*time.Millisecond) b.StartTimer() - for i := 1000000; i <1000000 + b.N; i++ { + b.N = 10000000 + for i := 0; i < b.N; i++ { tc.Set(strconv.Itoa(i), "bar", DefaultExpiration) } } + +/* +func BenchmarkLargeCache(b *testing.B) { + b.StopTimer() + tc := New(1*time.Millisecond, 0*time.Millisecond) + M := 1000000 + start := time.Now().UnixNano() + for i := 0; i < M; i++ { + tc.Set(strconv.Itoa(i), "bar", DefaultExpiration) + } + elapsed := (time.Now().UnixNano() - start)/1000000 + interval := elapsed/100 + b.Logf("Time to insert %d items: %d milliseconds", M, elapsed) + b.Logf("Interval: %d milliseconds", interval) + + tc = New(time.Duration(elapsed)*time.Millisecond, 0*time.Millisecond) + for i := 0; i < M; i++ { + tc.Set(strconv.Itoa(i), "bar", DefaultExpiration) + } + b.Logf("Cache size: %d", tc.ItemCount()) + items := tc.cache.items + tc = NewFrom(time.Duration(elapsed)*time.Millisecond, time.Duration(interval)*time.Millisecond, items) + + b.StartTimer() + for i := M; i Date: Tue, 1 Dec 2015 22:31:59 +0100 Subject: [PATCH 2/3] modified test --- cache_test.go | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/cache_test.go b/cache_test.go index 4333af4..8586253 100644 --- a/cache_test.go +++ b/cache_test.go @@ -1648,16 +1648,41 @@ func BenchmarkDeleteExpiredLoop(b *testing.B) { } } -func BenchmarkLargeCache(b *testing.B) { +func BenchmarkLargeCache01(b *testing.B) { + benchmarkLargeCache(b, 100000) +} + +func BenchmarkLargeCache02(b *testing.B) { + benchmarkLargeCache(b, 200000) +} + +func BenchmarkLargeCache05(b *testing.B) { + benchmarkLargeCache(b, 500000) +} + +func BenchmarkLargeCache10(b *testing.B) { + benchmarkLargeCache(b, 1000000) +} + +func BenchmarkLargeCache20(b *testing.B) { + benchmarkLargeCache(b, 2000000) +} + +func BenchmarkLargeCache50(b *testing.B) { + benchmarkLargeCache(b, 5000000) +} + +func benchmarkLargeCache(b *testing.B, nano int) { b.StopTimer() - tc := New(100*time.Millisecond, 5*time.Millisecond) + tc := New(100*time.Millisecond, time.Duration(nano)*time.Nanosecond) b.StartTimer() - b.N = 10000000 + b.N = 1000000 for i := 0; i < b.N; i++ { tc.Set(strconv.Itoa(i), "bar", DefaultExpiration) } } + /* func BenchmarkLargeCache(b *testing.B) { b.StopTimer() From faf83836bdb705862d053d3ddd08bc05183cb2dd Mon Sep 17 00:00:00 2001 From: Patrick Mylund Nielsen Date: Wed, 2 Dec 2015 14:32:12 -0500 Subject: [PATCH 3/3] Change GitHub repository URLs in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9cc4cc4..91f0087 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,13 @@ one) to recover from downtime quickly. (See the docs for `NewFrom()` for caveats ### Installation -`go get github.com/pmylund/go-cache` +`go get github.com/patrickmn/go-cache` ### Usage import ( "fmt" - "github.com/pmylund/go-cache" + "github.com/patrickmn/go-cache" "time" )