Compare commits

...

4 Commits

Author SHA1 Message Date
Patrick Mylund Nielsen 46f4078530 Fix incorrect key in concurrent benchmarks
Fixes #111
2019-10-04 15:21:08 -04:00
Patrick Mylund Nielsen 8026b575a9 LICENSE: Update copyright years 2019-10-04 15:15:23 -04:00
Patrick Mylund Nielsen 5633e08626 LICENSE: Update years 2018-08-15 01:31:27 -04:00
Patrick Mylund Nielsen 9f6ff22cff Fix benchmark for-loop shadowing 2018-05-27 00:33:50 -04:00
3 changed files with 9 additions and 9 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) 2012-2017 Patrick Mylund Nielsen and the go-cache contributors Copyright (c) 2012-2019 Patrick Mylund Nielsen and the go-cache contributors
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1555,7 +1555,7 @@ func benchmarkCacheGetManyConcurrent(b *testing.B, exp time.Duration) {
tc := New(exp, 0) tc := New(exp, 0)
keys := make([]string, n) keys := make([]string, n)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
k := "foo" + strconv.Itoa(n) k := "foo" + strconv.Itoa(i)
keys[i] = k keys[i] = k
tc.Set(k, "bar", DefaultExpiration) tc.Set(k, "bar", DefaultExpiration)
} }
@ -1563,12 +1563,12 @@ func benchmarkCacheGetManyConcurrent(b *testing.B, exp time.Duration) {
wg := new(sync.WaitGroup) wg := new(sync.WaitGroup)
wg.Add(n) wg.Add(n)
for _, v := range keys { for _, v := range keys {
go func() { go func(k string) {
for j := 0; j < each; j++ { for j := 0; j < each; j++ {
tc.Get(v) tc.Get(k)
} }
wg.Done() wg.Done()
}() }(v)
} }
b.StartTimer() b.StartTimer()
wg.Wait() wg.Wait()

View File

@ -65,7 +65,7 @@ func benchmarkShardedCacheGetManyConcurrent(b *testing.B, exp time.Duration) {
tsc := unexportedNewSharded(exp, 0, 20) tsc := unexportedNewSharded(exp, 0, 20)
keys := make([]string, n) keys := make([]string, n)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
k := "foo" + strconv.Itoa(n) k := "foo" + strconv.Itoa(i)
keys[i] = k keys[i] = k
tsc.Set(k, "bar", DefaultExpiration) tsc.Set(k, "bar", DefaultExpiration)
} }
@ -73,12 +73,12 @@ func benchmarkShardedCacheGetManyConcurrent(b *testing.B, exp time.Duration) {
wg := new(sync.WaitGroup) wg := new(sync.WaitGroup)
wg.Add(n) wg.Add(n)
for _, v := range keys { for _, v := range keys {
go func() { go func(k string) {
for j := 0; j < each; j++ { for j := 0; j < each; j++ {
tsc.Get(v) tsc.Get(k)
} }
wg.Done() wg.Done()
}() }(v)
} }
b.StartTimer() b.StartTimer()
wg.Wait() wg.Wait()