Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/playground: detect and run Benchmark functions #38731

Open
bcmills opened this issue Apr 28, 2020 · 0 comments
Open

x/playground: detect and run Benchmark functions #38731

bcmills opened this issue Apr 28, 2020 · 0 comments
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Apr 28, 2020

What did you do?

Wrote a Playground source file containing a Benchmark function, for which I wanted to see the allocations per operation (a number that does not depend in any way on the absolute running time of the program):
https://play.golang.org/p/LKZwUYcGLaG

package main

import (
	"runtime"
	"testing"
)

func BenchmarkAlloc(b *testing.B) {
	b.ReportAllocs()

	for n := b.N; n > 0; n-- {
		x := new(int)
		runtime.KeepAlive(x)
	}
}

What did you expect to see?

Output similar to go test -bench .:

goos: linux
goarch: amd64
pkg: example.com
BenchmarkAlloc-6        1000000000               0.285 ns/op           0 B/op          0 allocs/op
PASS
ok      example.com     0.346s

What did you see instead?

runtime.main_main·f: function main is undeclared in the main package

Go build failed.

6b1nRZe6KaY

CC @andybons @dmitshur @toothrot @cagedmantis

See previously #24311, #6511, #32403.

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. FeatureRequest labels Apr 28, 2020
@bcmills bcmills added this to the Backlog milestone Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

1 participant