Skip to content

Commit

Permalink
added RWMutex benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
OneOfOne committed Aug 27, 2014
1 parent deec6be commit 692fc11
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions sync/spinlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ func (mm *RWMutexMap) Get(i int) (b bool) {
const N = 1e3

var (
sm = SpinMap{m: map[int]bool{}}
mm = MutexMap{m: map[int]bool{}}
sm = SpinMap{m: map[int]bool{}}
mm = MutexMap{m: map[int]bool{}}
rwmm = RWMutexMap{m: map[int]bool{}}
)

func BenchmarkSpinL(b *testing.B) {
Expand Down Expand Up @@ -129,3 +130,23 @@ func BenchmarkMutex(b *testing.B) {
}
wg.Wait()
}

func BenchmarkRWMutex(b *testing.B) {
var wg sync.WaitGroup
for i := 0; i < b.N; i++ {
wg.Add(N * 2)
for i := 0; i < N; i++ {
go func(i int) {
rwmm.Add(i)
wg.Done()
}(i)
go mm.Get(i)
go func(i int) {
rwmm.Get(i - 1)
rwmm.Get(i + 1)
wg.Done()
}(i)
}
}
wg.Wait()
}

0 comments on commit 692fc11

Please sign in to comment.