Commit fcac8809 authored by Alex Brainman's avatar Alex Brainman

runtime: remove race out of BenchmarkChanToSyscallPing1ms

Fixes #15119

Change-Id: I31445bf282a5e2a160ff4e66c5a592b989a5798f
Reviewed-on: https://go-review.googlesource.com/21448Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent c4dda7e5
...@@ -901,18 +901,19 @@ func setEvent(h syscall.Handle) error { ...@@ -901,18 +901,19 @@ func setEvent(h syscall.Handle) error {
} }
func benchChanToSyscallPing(b *testing.B) { func benchChanToSyscallPing(b *testing.B) {
n := b.N
ch := make(chan int) ch := make(chan int)
event, err := createEvent() event, err := createEvent()
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
go func() { go func() {
for i := 0; i < b.N; i++ { for i := 0; i < n; i++ {
syscall.WaitForSingleObject(event, syscall.INFINITE) syscall.WaitForSingleObject(event, syscall.INFINITE)
ch <- 1 ch <- 1
} }
}() }()
for i := 0; i < b.N; i++ { for i := 0; i < n; i++ {
err := setEvent(event) err := setEvent(event)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
...@@ -932,6 +933,7 @@ func BenchmarkChanToSyscallPing15ms(b *testing.B) { ...@@ -932,6 +933,7 @@ func BenchmarkChanToSyscallPing15ms(b *testing.B) {
} }
func benchSyscallToSyscallPing(b *testing.B) { func benchSyscallToSyscallPing(b *testing.B) {
n := b.N
event1, err := createEvent() event1, err := createEvent()
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
...@@ -941,7 +943,7 @@ func benchSyscallToSyscallPing(b *testing.B) { ...@@ -941,7 +943,7 @@ func benchSyscallToSyscallPing(b *testing.B) {
b.Fatal(err) b.Fatal(err)
} }
go func() { go func() {
for i := 0; i < b.N; i++ { for i := 0; i < n; i++ {
syscall.WaitForSingleObject(event1, syscall.INFINITE) syscall.WaitForSingleObject(event1, syscall.INFINITE)
err := setEvent(event2) err := setEvent(event2)
if err != nil { if err != nil {
...@@ -949,7 +951,7 @@ func benchSyscallToSyscallPing(b *testing.B) { ...@@ -949,7 +951,7 @@ func benchSyscallToSyscallPing(b *testing.B) {
} }
} }
}() }()
for i := 0; i < b.N; i++ { for i := 0; i < n; i++ {
err := setEvent(event1) err := setEvent(event1)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
...@@ -969,15 +971,16 @@ func BenchmarkSyscallToSyscallPing15ms(b *testing.B) { ...@@ -969,15 +971,16 @@ func BenchmarkSyscallToSyscallPing15ms(b *testing.B) {
} }
func benchChanToChanPing(b *testing.B) { func benchChanToChanPing(b *testing.B) {
n := b.N
ch1 := make(chan int) ch1 := make(chan int)
ch2 := make(chan int) ch2 := make(chan int)
go func() { go func() {
for i := 0; i < b.N; i++ { for i := 0; i < n; i++ {
<-ch1 <-ch1
ch2 <- 1 ch2 <- 1
} }
}() }()
for i := 0; i < b.N; i++ { for i := 0; i < n; i++ {
ch1 <- 1 ch1 <- 1
<-ch2 <-ch2
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment