-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Theo
committed
Dec 30, 2017
1 parent
b0168d8
commit 92f0fa8
Showing
6 changed files
with
395 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package blockingQueues | ||
|
||
import ( | ||
. "gopkg.in/check.v1" | ||
"sync" | ||
) | ||
|
||
func benchmarkPut(c *C, writers int, readers int, q *BlockingQueue) { | ||
wg := sync.WaitGroup{} | ||
|
||
for writer := 0; writer < writers; writer++ { | ||
wg.Add(1) | ||
go func() { | ||
for i := 0; i < c.N; i++ { | ||
q.Put(i) | ||
} | ||
wg.Done() | ||
}() | ||
} | ||
|
||
for reader := 0; reader < readers; reader++ { | ||
wg.Add(1) | ||
go func() { | ||
for i := 0; i < c.N; i++ { | ||
q.Get() | ||
} | ||
wg.Done() | ||
}() | ||
} | ||
|
||
wg.Wait() | ||
} | ||
|
||
func benchmarkPutMoreWriters(c *C, writers int, readers int, q *BlockingQueue) { | ||
|
||
wg := sync.WaitGroup{} | ||
rest := writers - readers | ||
|
||
for writer := 0; writer < writers; writer++ { | ||
wg.Add(1) | ||
go func() { | ||
for i := 0; i < c.N; i++ { | ||
q.Put(i) | ||
} | ||
wg.Done() | ||
}() | ||
} | ||
|
||
for reader := 0; reader < readers; reader++ { | ||
wg.Add(1) | ||
go func() { | ||
for i := 0; i < c.N; i++ { | ||
q.Get() | ||
} | ||
wg.Done() | ||
}() | ||
} | ||
c.ResetTimer() | ||
for reader := 0; reader < rest; reader++ { | ||
wg.Add(1) | ||
go func() { | ||
for i := 0; i < c.N; i++ { | ||
q.Get() | ||
} | ||
wg.Done() | ||
}() | ||
} | ||
wg.Wait() | ||
|
||
} | ||
|
||
func benchmarkPutMoreReaders(c *C, writers int, readers int, q *BlockingQueue) { | ||
|
||
wg := sync.WaitGroup{} | ||
rest := readers - writers | ||
|
||
for writer := 0; writer < writers; writer++ { | ||
wg.Add(1) | ||
go func() { | ||
for i := 0; i < c.N; i++ { | ||
q.Put(i) | ||
} | ||
wg.Done() | ||
}() | ||
} | ||
|
||
for reader := 0; reader < readers; reader++ { | ||
wg.Add(1) | ||
go func() { | ||
for i := 0; i < c.N; i++ { | ||
q.Get() | ||
} | ||
wg.Done() | ||
}() | ||
} | ||
c.ResetTimer() | ||
|
||
for writer := 0; writer < rest; writer++ { | ||
wg.Add(1) | ||
go func() { | ||
for i := 0; i < c.N; i++ { | ||
q.Put(i) | ||
} | ||
wg.Done() | ||
}() | ||
} | ||
wg.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
package blockingQueues | ||
package blockingQueues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.