Skip to content

testing: Benchmark shows zero allocations #20863

@rogpeppe

Description

@rogpeppe

testing.Benchmark does not seem to produce valid memory stats any more:

The following program:

package main

import (
	"fmt"
	"testing"
)

var global *int

func main() {
	r := testing.Benchmark(func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			global = new(int)
		}
	})
	fmt.Printf("creating filter: %v\n", r.MemString())
}

always prints:

       0 B/op	       0 allocs/op

I'd expect it to print

       8 B/op	       1 allocs/op

like previous Go versions.

go version devel +eab99a8 Mon Jun 26 21:12:22 2017 +0000 linux/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions