Skip to content
Browse files

remove StartTimer/StopTimer from the bench loop

It can completely mess up the benchmark numbers for init functions that
were too small. Moreover, it could make the -benchtime estimates be way
off. For example, 'benchinit cmd/go' was taking over a minute to run the
benchmark, instead of the expected ~1s.

The benchtime estimate being off is likely the upstream issue

The fact that StartTimer and StopTimer are expensive is being tracked in
  • Loading branch information...
mvdan committed Jan 13, 2019
1 parent 7d17615 commit 3aca7ab656fe1fc816bf883266dd7d8ca1000279
Showing with 6 additions and 4 deletions.
  1. +6 −4 main.go
10 main.go
@@ -334,6 +334,11 @@ type toZero struct {
Offset, ZeroSize int64

// Don't use StartTimer and StopTimer, as they call ReadMemStats, which is way
// too expensive compared to most init functions.
// For example, on 'benchinit cmd/go', ReadMemStats was taking up over 90% of
// the cpu time, and throwing off all the numbers.

var benchTmpl = template.Must(template.New("").Parse(`
// Code generated by benchinit. DO NOT EDIT.
@@ -349,11 +354,8 @@ func BenchmarkInit(b *testing.B) {
for i := 0; i < b.N; i++ {
deinit() // get ready to run init again

0 comments on commit 3aca7ab

Please sign in to comment.
You can’t perform that action at this time.