From: Michael Anthony Knyszek Date: Thu, 16 Oct 2025 00:58:20 +0000 (+0000) Subject: internal/runtime/cgobench: add Go function call benchmark for comparison X-Git-Tag: go1.26rc1~282 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=710abf74da2a017423e35e416ab3fd05e6053bf3;p=gostls13.git internal/runtime/cgobench: add Go function call benchmark for comparison Change-Id: I0ada7fa02eb5f18a78da17bdcfc63333abbd8450 Reviewed-on: https://go-review.googlesource.com/c/go/+/713284 Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Auto-Submit: Michael Knyszek --- diff --git a/src/internal/runtime/cgobench/bench_test.go b/src/internal/runtime/cgobench/bench_test.go index 3b8f9a8ca3..0348ee0f41 100644 --- a/src/internal/runtime/cgobench/bench_test.go +++ b/src/internal/runtime/cgobench/bench_test.go @@ -11,13 +11,13 @@ import ( "testing" ) -func BenchmarkCgoCall(b *testing.B) { +func BenchmarkCall(b *testing.B) { for b.Loop() { cgobench.Empty() } } -func BenchmarkCgoCallParallel(b *testing.B) { +func BenchmarkCallParallel(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { cgobench.Empty() @@ -25,16 +25,30 @@ func BenchmarkCgoCallParallel(b *testing.B) { }) } +func BenchmarkCgoCall(b *testing.B) { + for b.Loop() { + cgobench.EmptyC() + } +} + +func BenchmarkCgoCallParallel(b *testing.B) { + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + cgobench.EmptyC() + } + }) +} + func BenchmarkCgoCallWithCallback(b *testing.B) { for b.Loop() { - cgobench.Callback() + cgobench.CallbackC() } } func BenchmarkCgoCallParallelWithCallback(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { - cgobench.Callback() + cgobench.CallbackC() } }) } diff --git a/src/internal/runtime/cgobench/funcs.go b/src/internal/runtime/cgobench/funcs.go index 91efa51278..b60f6f58fd 100644 --- a/src/internal/runtime/cgobench/funcs.go +++ b/src/internal/runtime/cgobench/funcs.go @@ -19,14 +19,18 @@ static void callback() { */ import "C" -func Empty() { +func EmptyC() { C.empty() } -func Callback() { +func CallbackC() { C.callback() } //export go_empty_callback func go_empty_callback() { } + +//go:noinline +func Empty() { +}