Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1319)

Side by Side Diff: src/pkg/sync/waitgroup_test.go

Issue 96910043: code review 96910043: testing: RunParallel and SetParallelism are misleading. (Closed)
Patch Set: diff -r 7f529f73708a http://code.google.com/p/go Created 9 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/sync/rwmutex_test.go ('k') | src/pkg/testing/benchmark.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package sync_test 5 package sync_test
6 6
7 import ( 7 import (
8 . "sync" 8 . "sync"
9 "sync/atomic" 9 "sync/atomic"
10 "testing" 10 "testing"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 t.Fatal("Spurious wakeup from Wait") 83 t.Fatal("Spurious wakeup from Wait")
84 } 84 }
85 } 85 }
86 } 86 }
87 87
88 func BenchmarkWaitGroupUncontended(b *testing.B) { 88 func BenchmarkWaitGroupUncontended(b *testing.B) {
89 type PaddedWaitGroup struct { 89 type PaddedWaitGroup struct {
90 WaitGroup 90 WaitGroup
91 pad [128]uint8 91 pad [128]uint8
92 } 92 }
93 » b.RunParallel(func(pb *testing.PB) { 93 » b.RunConcurrent(func(pb *testing.PB) {
94 var wg PaddedWaitGroup 94 var wg PaddedWaitGroup
95 for pb.Next() { 95 for pb.Next() {
96 wg.Add(1) 96 wg.Add(1)
97 wg.Done() 97 wg.Done()
98 wg.Wait() 98 wg.Wait()
99 } 99 }
100 }) 100 })
101 } 101 }
102 102
103 func benchmarkWaitGroupAddDone(b *testing.B, localWork int) { 103 func benchmarkWaitGroupAddDone(b *testing.B, localWork int) {
104 var wg WaitGroup 104 var wg WaitGroup
105 » b.RunParallel(func(pb *testing.PB) { 105 » b.RunConcurrent(func(pb *testing.PB) {
106 foo := 0 106 foo := 0
107 for pb.Next() { 107 for pb.Next() {
108 wg.Add(1) 108 wg.Add(1)
109 for i := 0; i < localWork; i++ { 109 for i := 0; i < localWork; i++ {
110 foo *= 2 110 foo *= 2
111 foo /= 2 111 foo /= 2
112 } 112 }
113 wg.Done() 113 wg.Done()
114 } 114 }
115 _ = foo 115 _ = foo
116 }) 116 })
117 } 117 }
118 118
119 func BenchmarkWaitGroupAddDone(b *testing.B) { 119 func BenchmarkWaitGroupAddDone(b *testing.B) {
120 benchmarkWaitGroupAddDone(b, 0) 120 benchmarkWaitGroupAddDone(b, 0)
121 } 121 }
122 122
123 func BenchmarkWaitGroupAddDoneWork(b *testing.B) { 123 func BenchmarkWaitGroupAddDoneWork(b *testing.B) {
124 benchmarkWaitGroupAddDone(b, 100) 124 benchmarkWaitGroupAddDone(b, 100)
125 } 125 }
126 126
127 func benchmarkWaitGroupWait(b *testing.B, localWork int) { 127 func benchmarkWaitGroupWait(b *testing.B, localWork int) {
128 var wg WaitGroup 128 var wg WaitGroup
129 » b.RunParallel(func(pb *testing.PB) { 129 » b.RunConcurrent(func(pb *testing.PB) {
130 foo := 0 130 foo := 0
131 for pb.Next() { 131 for pb.Next() {
132 wg.Wait() 132 wg.Wait()
133 for i := 0; i < localWork; i++ { 133 for i := 0; i < localWork; i++ {
134 foo *= 2 134 foo *= 2
135 foo /= 2 135 foo /= 2
136 } 136 }
137 } 137 }
138 _ = foo 138 _ = foo
139 }) 139 })
140 } 140 }
141 141
142 func BenchmarkWaitGroupWait(b *testing.B) { 142 func BenchmarkWaitGroupWait(b *testing.B) {
143 benchmarkWaitGroupWait(b, 0) 143 benchmarkWaitGroupWait(b, 0)
144 } 144 }
145 145
146 func BenchmarkWaitGroupWaitWork(b *testing.B) { 146 func BenchmarkWaitGroupWaitWork(b *testing.B) {
147 benchmarkWaitGroupWait(b, 100) 147 benchmarkWaitGroupWait(b, 100)
148 } 148 }
OLDNEW
« no previous file with comments | « src/pkg/sync/rwmutex_test.go ('k') | src/pkg/testing/benchmark.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b