internal/runtime/cgobench: add cgo callback benchmark

Change-Id: I43ea575aff87a3e420477cb26d35185d03df5ccc
Reviewed-on: https://go-review.googlesource.com/c/go/+/713283
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Michael Anthony Knyszek 2025-10-15 21:19:13 +00:00 committed by Gopher Robot
parent 5f8fdb720c
commit 17b57078ab
2 changed files with 29 additions and 0 deletions

View file

@ -24,3 +24,17 @@ func BenchmarkCgoCallParallel(b *testing.B) {
} }
}) })
} }
func BenchmarkCgoCallWithCallback(b *testing.B) {
for b.Loop() {
cgobench.Callback()
}
}
func BenchmarkCgoCallParallelWithCallback(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
cgobench.Callback()
}
})
}

View file

@ -9,9 +9,24 @@ package cgobench
/* /*
static void empty() { static void empty() {
} }
void go_empty_callback();
static void callback() {
go_empty_callback();
}
*/ */
import "C" import "C"
func Empty() { func Empty() {
C.empty() C.empty()
} }
func Callback() {
C.callback()
}
//export go_empty_callback
func go_empty_callback() {
}