]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add cgo call benchmark
authorMichael Anthony Knyszek <mknyszek@google.com>
Mon, 3 Feb 2025 15:42:55 +0000 (15:42 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 30 Jul 2025 20:37:28 +0000 (13:37 -0700)
Change-Id: I12d2ae7dd6a33ecb7110b7d090871e7143fd609f
Reviewed-on: https://go-review.googlesource.com/c/go/+/646196
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/go/build/deps_test.go
src/internal/runtime/cgobench/bench_test.go [new file with mode: 0644]
src/internal/runtime/cgobench/funcs.go [new file with mode: 0644]

index e8bdfe7c1273d64a8afa048cc4751aef91784f93..00e6e562e541789345560d2d9da0e5e34df3df23 100644 (file)
@@ -796,6 +796,7 @@ var depsRules = `
        FMT < math/big/internal/asmgen;
 
        FMT, testing < internal/cgrouptest;
+       C, CGO < internal/runtime/cgobench;
 `
 
 // listStdPkgs returns the same list of packages as "go list std".
diff --git a/src/internal/runtime/cgobench/bench_test.go b/src/internal/runtime/cgobench/bench_test.go
new file mode 100644 (file)
index 0000000..b4d8efe
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build cgo
+
+package cgobench_test
+
+import (
+       "internal/runtime/cgobench"
+       "testing"
+)
+
+func BenchmarkCgoCall(b *testing.B) {
+       for b.Loop() {
+               cgobench.Empty()
+       }
+}
+
+func BenchmarkCgoCallParallel(b *testing.B) {
+       b.RunParallel(func(pb *testing.PB) {
+               for pb.Next() {
+                       cgobench.Empty()
+               }
+       })
+}
diff --git a/src/internal/runtime/cgobench/funcs.go b/src/internal/runtime/cgobench/funcs.go
new file mode 100644 (file)
index 0000000..db68518
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build cgo
+
+package cgobench
+
+/*
+static void empty() {
+}
+*/
+import "C"
+
+func Empty() {
+       C.empty()
+}