aboutsummaryrefslogtreecommitdiff
path: root/src/internal/runtime
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2025-10-16 00:58:20 +0000
committerGopher Robot <gobot@golang.org>2025-11-14 11:15:35 -0800
commit710abf74da2a017423e35e416ab3fd05e6053bf3 (patch)
tree94925ed1b097ca70cd1decae6f482cf46d6dcf8d /src/internal/runtime
parentb24aec598b9777de6044cf4f52042d3b3acc0f35 (diff)
downloadgo-710abf74da2a017423e35e416ab3fd05e6053bf3.tar.xz
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 <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/internal/runtime')
-rw-r--r--src/internal/runtime/cgobench/bench_test.go22
-rw-r--r--src/internal/runtime/cgobench/funcs.go8
2 files changed, 24 insertions, 6 deletions
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() {
+}