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

Delta Between Two Patch Sets: src/pkg/sync/once_test.go

Issue 4650054: code review 4650054: sync: add benchmark for Once. (Closed)
Left Patch Set: diff -r b295b8bda20b https://go.googlecode.com/hg/ Created 13 years, 8 months ago
Right Patch Set: diff -r 9e53a1312e25 https://go.googlecode.com/hg/ Created 13 years, 8 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | 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
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 sync_test 5 package sync_test
6 6
7 import ( 7 import (
8 . "sync" 8 . "sync"
9 "sync/atomic" 9 "sync/atomic"
10 "runtime" 10 "runtime"
(...skipping 22 matching lines...) Expand all
33 for i := 0; i < N; i++ { 33 for i := 0; i < N; i++ {
34 <-c 34 <-c
35 } 35 }
36 if *o != 1 { 36 if *o != 1 {
37 t.Errorf("once failed: %d is not 1", *o) 37 t.Errorf("once failed: %d is not 1", *o)
38 } 38 }
39 } 39 }
40 40
41 func BenchmarkOnce(b *testing.B) { 41 func BenchmarkOnce(b *testing.B) {
42 const CallsPerSched = 1000 42 const CallsPerSched = 1000
43 b.SetBytes(1)
rsc 2011/06/27 15:59:24 Since this is not processing data, it seems better
44 procs := runtime.GOMAXPROCS(-1) 43 procs := runtime.GOMAXPROCS(-1)
45 N := int32(b.N / CallsPerSched) 44 N := int32(b.N / CallsPerSched)
rsc 2011/06/27 15:59:24 Should this be b.N / CallsPerSched / procs?
46 » once := new(Once) 45 » var once Once
rsc 2011/06/27 15:59:24 var once Once
47 f := func() {} 46 f := func() {}
48 c := make(chan bool, procs) 47 c := make(chan bool, procs)
49 for p := 0; p < procs; p++ { 48 for p := 0; p < procs; p++ {
50 go func() { 49 go func() {
51 for atomic.AddInt32(&N, -1) >= 0 { 50 for atomic.AddInt32(&N, -1) >= 0 {
52 runtime.Gosched() 51 runtime.Gosched()
53 for g := 0; g < CallsPerSched; g++ { 52 for g := 0; g < CallsPerSched; g++ {
54 once.Do(f) 53 once.Do(f)
55 } 54 }
56 } 55 }
57 c <- true 56 c <- true
58 }() 57 }()
59 } 58 }
60 for p := 0; p < procs; p++ { 59 for p := 0; p < procs; p++ {
61 <-c 60 <-c
62 } 61 }
63 } 62 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

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