plugin/pkg/cache: smarter locking (#1164)
Make the locking slightly smarter in Evict and add benchmark function. Seems a bit faster (there was some variance while performing these benchmarks) Master: BenchmarkCache-2 1000000 2317 ns/op 0 B/op 0 allocs/op BenchmarkCache-2 1000000 2032 ns/op 0 B/op 0 allocs/op This branch: BenchmarkCache-2 1000000 1806 ns/op 0 B/op 0 allocs/op BenchmarkCache-2 1000000 1809 ns/op 0 B/op 0 allocs/op
This commit is contained in:
parent
cb5e82b82e
commit
5aa0d55e72
2 changed files with 17 additions and 4 deletions
10
plugin/pkg/cache/cache_test.go
vendored
10
plugin/pkg/cache/cache_test.go
vendored
|
@ -29,3 +29,13 @@ func TestCacheLen(t *testing.T) {
|
|||
t.Fatalf("Cache size should %d, got %d", 2, l)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCache(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
c := New(4)
|
||||
for n := 0; n < b.N; n++ {
|
||||
c.Add(1, 1)
|
||||
c.Get(1)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue