MCPcopy Create free account
hub / github.com/gorilla/context / benchmarkMutex

Function benchmarkMutex

context_test.go:103–129  ·  view source on GitHub ↗
(b *testing.B, numReaders, numWriters, iterations int)

Source from the content-addressed store, hash-verified

101}
102
103func benchmarkMutex(b *testing.B, numReaders, numWriters, iterations int) {
104
105 b.StopTimer()
106 r, _ := http.NewRequest("GET", "http://localhost:8080/", nil)
107 done := make(chan struct{})
108 b.StartTimer()
109
110 for i := 0; i < b.N; i++ {
111 wait := make(chan struct{})
112
113 for i := 0; i < numReaders; i++ {
114 go parallelReader(r, "test", iterations, wait, done)
115 }
116
117 for i := 0; i < numWriters; i++ {
118 go parallelWriter(r, "test", "123", iterations, wait, done)
119 }
120
121 close(wait)
122
123 for i := 0; i < numReaders+numWriters; i++ {
124 <-done
125 }
126
127 }
128
129}
130
131func BenchmarkMutexSameReadWrite1(b *testing.B) {
132 benchmarkMutex(b, 1, 1, 32)

Callers 9

BenchmarkMutex1Function · 0.85
BenchmarkMutex2Function · 0.85
BenchmarkMutex3Function · 0.85
BenchmarkMutex4Function · 0.85
BenchmarkMutex5Function · 0.85
BenchmarkMutex6Function · 0.85

Calls 2

parallelReaderFunction · 0.85
parallelWriterFunction · 0.85

Tested by

no test coverage detected