Skip to content

Commit 70a2ff7

Browse files
mknyszekgopherbot
authored andcommitted
runtime: add cgo call benchmark
Change-Id: I12d2ae7dd6a33ecb7110b7d090871e7143fd609f Reviewed-on: https://go-review.googlesource.com/c/go/+/646196 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Michael Knyszek <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent 69338a3 commit 70a2ff7

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/go/build/deps_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ var depsRules = `
796796
FMT < math/big/internal/asmgen;
797797
798798
FMT, testing < internal/cgrouptest;
799+
C, CGO < internal/runtime/cgobench;
799800
`
800801

801802
// listStdPkgs returns the same list of packages as "go list std".
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build cgo
6+
7+
package cgobench_test
8+
9+
import (
10+
"internal/runtime/cgobench"
11+
"testing"
12+
)
13+
14+
func BenchmarkCgoCall(b *testing.B) {
15+
for b.Loop() {
16+
cgobench.Empty()
17+
}
18+
}
19+
20+
func BenchmarkCgoCallParallel(b *testing.B) {
21+
b.RunParallel(func(pb *testing.PB) {
22+
for pb.Next() {
23+
cgobench.Empty()
24+
}
25+
})
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build cgo
6+
7+
package cgobench
8+
9+
/*
10+
static void empty() {
11+
}
12+
*/
13+
import "C"
14+
15+
func Empty() {
16+
C.empty()
17+
}

0 commit comments

Comments
 (0)