From 70a2ff76485477211397ae6399bee06101bc5935 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Mon, 3 Feb 2025 15:42:55 +0000 Subject: [PATCH] runtime: add cgo call benchmark Change-Id: I12d2ae7dd6a33ecb7110b7d090871e7143fd609f Reviewed-on: https://go-review.googlesource.com/c/go/+/646196 LUCI-TryBot-Result: Go LUCI Auto-Submit: Michael Knyszek Reviewed-by: Michael Pratt --- src/go/build/deps_test.go | 1 + src/internal/runtime/cgobench/bench_test.go | 26 +++++++++++++++++++++ src/internal/runtime/cgobench/funcs.go | 17 ++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 src/internal/runtime/cgobench/bench_test.go create mode 100644 src/internal/runtime/cgobench/funcs.go diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index e8bdfe7c12..00e6e562e5 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -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 index 0000000000..b4d8efec5e --- /dev/null +++ b/src/internal/runtime/cgobench/bench_test.go @@ -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 index 0000000000..db685180a1 --- /dev/null +++ b/src/internal/runtime/cgobench/funcs.go @@ -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() +} -- 2.51.0