]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add Func method benchmarks
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 21 Sep 2021 21:31:09 +0000 (14:31 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 27 Sep 2021 20:56:37 +0000 (20:56 +0000)
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>
src/runtime/symtab_test.go

index ffa07c7f3a9f8dca3ab1323bdfe6cbd5269a2c39..99ff0d4420b1caa9a246cc98368109533a89ee7d 100644 (file)
@@ -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)
+                       }
+               }
+       })
+}