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

Delta Between Two Patch Sets: src/pkg/time/sleep_test.go

Issue 12876047: code review 12876047: time: lower level interface to Timer: embedding, compac...
Left Patch Set: Created 10 years, 7 months ago
Right Patch Set: diff -r 9810b5abd0ab https://code.google.com/p/go Created 10 years, 7 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:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/time/sleep.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 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 time_test 5 package time_test
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "fmt" 9 "fmt"
10 "runtime" 10 "runtime"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 benchmark(b, func(n int) { 139 benchmark(b, func(n int) {
140 var wg sync.WaitGroup 140 var wg sync.WaitGroup
141 wg.Add(n) 141 wg.Add(n)
142 for i := 0; i < n; i++ { 142 for i := 0; i < n; i++ {
143 AfterFunc(0, wg.Done) 143 AfterFunc(0, wg.Done)
144 } 144 }
145 wg.Wait() 145 wg.Wait()
146 }) 146 })
147 } 147 }
148 148
149 type expirePointer struct {
150 t *Timer
151 }
152
153 func (e *expirePointer) Expire() {
154 }
155
156 type expireEmbed struct {
157 t EmbedTimer
158 }
159
160 func (e *expireEmbed) Expire() {
161 }
162
163 func BenchmarkPointerStop(b *testing.B) {
164 benchmark(b, func(n int) {
165 e := make([]expirePointer, n)
166 for i := range e {
167 e[i].t = AfterFunc(Hour, e[i].Expire)
168 }
169 for i := range e {
170 e[i].t.Stop()
171 e[i].t = nil
172 }
173 })
174 }
175
176 func BenchmarkEmbedStop(b *testing.B) {
177 benchmark(b, func(n int) {
178 e := make([]expireEmbed, n)
179 for i := range e {
180 e[i].t.SetupExpire(Hour, &e[i])
181 }
182 for i := range e {
183 e[i].t.Deinitialize()
184 }
185 })
186 }
187
149 func BenchmarkStartStop(b *testing.B) { 188 func BenchmarkStartStop(b *testing.B) {
150 benchmark(b, func(n int) { 189 benchmark(b, func(n int) {
151 timers := make([]*Timer, n) 190 timers := make([]*Timer, n)
152 for i := 0; i < n; i++ { 191 for i := 0; i < n; i++ {
153 timers[i] = AfterFunc(Hour, nil) 192 timers[i] = AfterFunc(Hour, nil)
154 } 193 }
155 194
156 for i := 0; i < n; i++ { 195 for i := 0; i < n; i++ {
157 timers[i].Stop() 196 timers[i].Stop()
158 } 197 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 if r := recover(); r == nil { 428 if r := recover(); r == nil {
390 t.Error("Expected panic, but none happened.") 429 t.Error("Expected panic, but none happened.")
391 } 430 }
392 }() 431 }()
393 432
394 // cause a panic due to a segfault 433 // cause a panic due to a segfault
395 var timer *Timer 434 var timer *Timer
396 timer.Stop() 435 timer.Stop()
397 t.Error("Should be unreachable.") 436 t.Error("Should be unreachable.")
398 } 437 }
LEFTRIGHT

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