1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

pkg/locker: add benchmarks

Signed-off-by: Alexander Morozov <lk4d4math@gmail.com>
This commit is contained in:
Alexander Morozov 2017-10-02 11:14:42 -07:00
parent 1e94a4862e
commit 889cfd1b44

View file

@ -1,6 +1,8 @@
package locker
import (
"math/rand"
"strconv"
"sync"
"testing"
"time"
@ -122,3 +124,38 @@ func TestLockerConcurrency(t *testing.T) {
t.Fatalf("lock should not exist: %v", ctr)
}
}
func BenchmarkLocker(b *testing.B) {
l := New()
for i := 0; i < b.N; i++ {
l.Lock("test")
l.Unlock("test")
}
}
func BenchmarkLockerParallel(b *testing.B) {
l := New()
b.SetParallelism(128)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
l.Lock("test")
l.Unlock("test")
}
})
}
func BenchmarkLockerMoreKeys(b *testing.B) {
l := New()
var keys []string
for i := 0; i < 64; i++ {
keys = append(keys, strconv.Itoa(i))
}
b.SetParallelism(128)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
k := keys[rand.Intn(len(keys))]
l.Lock(k)
l.Unlock(k)
}
})
}