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:
parent
1e94a4862e
commit
889cfd1b44
1 changed files with 37 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue