Skip to content

Commit

Permalink
Report allocs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Gajewski committed Nov 2, 2016
1 parent d3bfe18 commit 216b1fe
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bigcache_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func BenchmarkWriteToCacheWith1Shard(b *testing.B) {
func BenchmarkWriteToLimitedCacheWithSmallInitSizeAnd1Shard(b *testing.B) {
m := blob('a', 1024)
cache, _ := NewBigCache(Config{1, 100 * time.Second, 100, 256, false, nil, 1, nil})

b.ReportAllocs()
for i := 0; i < b.N; i++ {
cache.Set(fmt.Sprintf("key-%d", i), m)
}
Expand All @@ -25,6 +27,8 @@ func BenchmarkWriteToLimitedCacheWithSmallInitSizeAnd1Shard(b *testing.B) {
func BenchmarkWriteToUnlimitedCacheWithSmallInitSizeAnd1Shard(b *testing.B) {
m := blob('a', 1024)
cache, _ := NewBigCache(Config{1, 100 * time.Second, 100, 256, false, nil, 0, nil})

b.ReportAllocs()
for i := 0; i < b.N; i++ {
cache.Set(fmt.Sprintf("key-%d", i), m)
}
Expand All @@ -47,6 +51,7 @@ func BenchmarkReadFromCache(b *testing.B) {
}

func BenchmarkIterateOverCache(b *testing.B) {

m := blob('a', 1)

for _, shards := range []int{512, 1024, 8192} {
Expand All @@ -61,6 +66,8 @@ func BenchmarkIterateOverCache(b *testing.B) {
it := cache.Iterator()

b.RunParallel(func(pb *testing.PB) {
b.ReportAllocs()

for pb.Next() {
if it.SetNext() {
it.Value()
Expand All @@ -82,6 +89,8 @@ func writeToCache(b *testing.B, shards int, lifeWindow time.Duration, requestsIn
b.RunParallel(func(pb *testing.PB) {
id := rand.Int()
counter := 0

b.ReportAllocs()
for pb.Next() {
cache.Set(fmt.Sprintf("key-%d-%d", id, counter), message)
counter = counter + 1
Expand All @@ -97,6 +106,8 @@ func readFromCache(b *testing.B, shards int) {
b.ResetTimer()

b.RunParallel(func(pb *testing.PB) {
b.ReportAllocs()

for pb.Next() {
cache.Get(strconv.Itoa(rand.Intn(b.N)))
}
Expand Down

0 comments on commit 216b1fe

Please sign in to comment.