mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
testing: ease writing parallel benchmarks
Add b.RunParallel function that captures parallel benchmark boilerplate: creates worker goroutines, joins worker goroutines, distributes work among them in an efficient way, auto-tunes grain size. Fixes #7090. R=bradfitz, iant, josharian, tracey.brendan, r, rsc, gobot CC=golang-codereviews https://golang.org/cl/57270043
This commit is contained in:
parent
a1aee55bd1
commit
c3922f0a63
5 changed files with 236 additions and 145 deletions
|
|
@ -43,6 +43,7 @@
|
|||
//
|
||||
// If a benchmark needs some expensive setup before running, the timer
|
||||
// may be reset:
|
||||
//
|
||||
// func BenchmarkBigLen(b *testing.B) {
|
||||
// big := NewBig()
|
||||
// b.ResetTimer()
|
||||
|
|
@ -51,6 +52,21 @@
|
|||
// }
|
||||
// }
|
||||
//
|
||||
// If a benchmark needs to test performance in a parallel setting, it may use
|
||||
// the RunParallel helper function; such benchmarks are intended to be used with
|
||||
// the go test -cpu flag:
|
||||
//
|
||||
// func BenchmarkTemplateParallel(b *testing.B) {
|
||||
// templ := template.Must(template.New("test").Parse("Hello, {{.}}!"))
|
||||
// b.RunParallel(func(pb *testing.PB) {
|
||||
// var buf bytes.Buffer
|
||||
// for pb.Next() {
|
||||
// buf.Reset()
|
||||
// templ.Execute(&buf, "World")
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// Examples
|
||||
//
|
||||
// The package also runs and verifies example code. Example functions may
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue