aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/chan_test.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2014-12-08 10:11:08 -0800
committerKeith Randall <khr@golang.org>2014-12-08 19:20:12 +0000
commit8eb8b40a4965c0bd5f96dfdfc5b037925f630c2d (patch)
treee75d583cbdb939d973d7237c4c1a5163af031d80 /src/runtime/chan_test.go
parent006ceb2f1dd64e75134347ae9a73be397ff8a2ed (diff)
downloadgo-8eb8b40a4965c0bd5f96dfdfc5b037925f630c2d.tar.gz
go-8eb8b40a4965c0bd5f96dfdfc5b037925f630c2d.zip
runtime: use doubly-linked lists for channel send/recv queues.
Avoids a potential O(n^2) performance problem when dequeueing from very popular channels. benchmark old ns/op new ns/op delta BenchmarkChanPopular 2563782 627201 -75.54% Change-Id: I231aaeafea0ecd93d27b268a0b2128530df3ddd6 Reviewed-on: https://go-review.googlesource.com/1200 Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/runtime/chan_test.go')
-rw-r--r--src/runtime/chan_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/runtime/chan_test.go b/src/runtime/chan_test.go
index e689ceaed1..8a357c1f23 100644
--- a/src/runtime/chan_test.go
+++ b/src/runtime/chan_test.go
@@ -818,3 +818,26 @@ func BenchmarkChanSem(b *testing.B) {
}
})
}
+
+func BenchmarkChanPopular(b *testing.B) {
+ const n = 1000
+ c := make(chan bool)
+ var a []chan bool
+ for j := 0; j < n; j++ {
+ d := make(chan bool)
+ a = append(a, d)
+ go func() {
+ for i := 0; i < b.N; i++ {
+ select {
+ case <-c:
+ case <-d:
+ }
+ }
+ }()
+ }
+ for i := 0; i < b.N; i++ {
+ for _, d := range a {
+ d <- true
+ }
+ }
+}