75
func BenchmarkUncontendedMutex(b *testing.B) {
77
HammerMutex(m, b.N, make(chan bool, 2))
80
func BenchmarkContendedMutex(b *testing.B) {
87
go HammerMutex(m, b.N/2, c)
88
go HammerMutex(m, b.N/2, c)
93
76
func TestMutexPanic(t *testing.T) {
95
78
if recover() == nil {
89
func BenchmarkMutexUncontended(b *testing.B) {
90
type PaddedMutex struct {
94
const CallsPerSched = 1000
95
procs := runtime.GOMAXPROCS(-1)
96
N := int32(b.N / CallsPerSched)
97
c := make(chan bool, procs)
98
for p := 0; p < procs; p++ {
101
for atomic.AddInt32(&N, -1) >= 0 {
103
for g := 0; g < CallsPerSched; g++ {
111
for p := 0; p < procs; p++ {
116
func benchmarkMutex(b *testing.B, slack, work bool) {
122
procs := runtime.GOMAXPROCS(-1)
124
procs *= GoroutineSlack
126
N := int32(b.N / CallsPerSched)
127
c := make(chan bool, procs)
129
for p := 0; p < procs; p++ {
132
for atomic.AddInt32(&N, -1) >= 0 {
134
for g := 0; g < CallsPerSched; g++ {
138
for i := 0; i < LocalWork; i++ {
148
for p := 0; p < procs; p++ {
153
func BenchmarkMutex(b *testing.B) {
154
benchmarkMutex(b, false, false)
157
func BenchmarkMutexSlack(b *testing.B) {
158
benchmarkMutex(b, true, false)
161
func BenchmarkMutexWork(b *testing.B) {
162
benchmarkMutex(b, false, true)
165
func BenchmarkMutexWorkSlack(b *testing.B) {
166
benchmarkMutex(b, true, true)