mirror of
https://github.com/golang/go
synced 2024-11-23 18:30:06 -07:00
runtime: add Func method benchmarks
Change-Id: Ib76872c22b1be9e611199b84fd96b59beedf786c Reviewed-on: https://go-review.googlesource.com/c/go/+/351457 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
2dda92ff6f
commit
f961d8e5b1
@ -250,3 +250,35 @@ func TestFunctionAlignmentTraceback(t *testing.T) {
|
||||
t.Errorf("frames.Next() got %+v want %+v", frame.Func, f)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkFunc(b *testing.B) {
|
||||
pc, _, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
b.Fatal("failed to look up PC")
|
||||
}
|
||||
f := runtime.FuncForPC(pc)
|
||||
b.Run("Name", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
name := f.Name()
|
||||
if name != "runtime_test.BenchmarkFunc" {
|
||||
b.Fatalf("unexpected name %q", name)
|
||||
}
|
||||
}
|
||||
})
|
||||
b.Run("Entry", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
pc := f.Entry()
|
||||
if pc == 0 {
|
||||
b.Fatal("zero PC")
|
||||
}
|
||||
}
|
||||
})
|
||||
b.Run("FileLine", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
file, line := f.FileLine(pc)
|
||||
if !strings.HasSuffix(file, "symtab_test.go") || line == 0 {
|
||||
b.Fatalf("unexpected file/line %q:%d", file, line)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user