Skip to content

Commit

Permalink
bench: add parallel perf test for lock contention
Browse files Browse the repository at this point in the history
we expect to see lock contention stemming from the usage of global rand.
  • Loading branch information
mroth committed Jun 20, 2020
1 parent 6125a88 commit 2526e09
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions weightedrand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ func BenchmarkPick(b *testing.B) {
}
}

func BenchmarkPickParallel(b *testing.B) {
for n := BMminChoices; n <= BMmaxChoices; n *= 10 {
b.Run(strconv.Itoa(n), func(b *testing.B) {
choices := mockChoices(n)
chooser := NewChooser(choices...)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
chooser.Pick()
}
})
})
}
}

func mockChoices(n int) []Choice {
choices := make([]Choice, 0, n)
for i := 0; i < n; i++ {
Expand Down

0 comments on commit 2526e09

Please sign in to comment.