Skip to content

Commit

Permalink
Add parallel benchmarks (#34)
Browse files Browse the repository at this point in the history
Atomic operations tend to be fast when there's no contention but get a
lot slower with contention, so add tests which run the same stress test
in parallel.
  • Loading branch information
prashantv committed Nov 14, 2017
1 parent 0ee2c2d commit 54e9e20
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,20 @@ func BenchmarkStress(b *testing.B) {
for name, ff := range _stressTests {
b.Run(name, func(b *testing.B) {
f := ff()
for i := 0; i < b.N; i++ {
f()
}

b.Run("serial", func(b *testing.B) {
for i := 0; i < b.N; i++ {
f()
}
})

b.Run("parallel", func(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
f()
}
})
})
})
}
}
Expand Down

0 comments on commit 54e9e20

Please sign in to comment.