From: Michael Anthony Knyszek Date: Wed, 15 Oct 2025 21:19:13 +0000 (+0000) Subject: internal/runtime/cgobench: add cgo callback benchmark X-Git-Tag: go1.26rc1~397 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=17b57078ab5388d830c28965717c3cc52bb845e1;p=gostls13.git internal/runtime/cgobench: add cgo callback benchmark Change-Id: I43ea575aff87a3e420477cb26d35185d03df5ccc Reviewed-on: https://go-review.googlesource.com/c/go/+/713283 Reviewed-by: Michael Pratt Auto-Submit: Michael Knyszek LUCI-TryBot-Result: Go LUCI --- diff --git a/src/internal/runtime/cgobench/bench_test.go b/src/internal/runtime/cgobench/bench_test.go index b4d8efec5e..3b8f9a8ca3 100644 --- a/src/internal/runtime/cgobench/bench_test.go +++ b/src/internal/runtime/cgobench/bench_test.go @@ -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() + } + }) +} diff --git a/src/internal/runtime/cgobench/funcs.go b/src/internal/runtime/cgobench/funcs.go index db685180a1..91efa51278 100644 --- a/src/internal/runtime/cgobench/funcs.go +++ b/src/internal/runtime/cgobench/funcs.go @@ -9,9 +9,24 @@ package cgobench /* static void empty() { } + +void go_empty_callback(); + +static void callback() { + go_empty_callback(); +} + */ import "C" func Empty() { C.empty() } + +func Callback() { + C.callback() +} + +//export go_empty_callback +func go_empty_callback() { +}