Skip to content

Commit

Permalink
record per-rpc rtt in benchmark_test
Browse files Browse the repository at this point in the history
  • Loading branch information
iamqizhao committed Apr 29, 2015
1 parent 93ec6da commit f29a6f2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions benchmark/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,30 @@ func run(b *testing.B, maxConcurrentCalls int, caller func(testpb.TestServiceCli
}

ch := make(chan int, maxConcurrentCalls*4)
var wg sync.WaitGroup
var (
mu sync.Mutex
wg sync.WaitGroup
)
wg.Add(maxConcurrentCalls)

// Distribute the b.N calls over maxConcurrentCalls workers.
for i := 0; i < maxConcurrentCalls; i++ {
go func() {
for _ = range ch {
start := time.Now()
caller(tc)
elapse := time.Since(start)
mu.Lock()
s.Add(elapse)
mu.Unlock()
}
wg.Done()
}()
}
for i := 0; i < b.N; i++ {
b.StartTimer()
start := time.Now()
ch <- i
elapsed := time.Since(start)
b.StopTimer()
s.Add(elapsed)
}
close(ch)
wg.Wait()
Expand Down

0 comments on commit f29a6f2

Please sign in to comment.