Skip to content

Commit 17b5707

Browse files
mknyszekgopherbot
authored andcommitted
internal/runtime/cgobench: add cgo callback benchmark
Change-Id: I43ea575aff87a3e420477cb26d35185d03df5ccc Reviewed-on: https://go-review.googlesource.com/c/go/+/713283 Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 5f8fdb7 commit 17b5707

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/internal/runtime/cgobench/bench_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@ func BenchmarkCgoCallParallel(b *testing.B) {
2424
}
2525
})
2626
}
27+
28+
func BenchmarkCgoCallWithCallback(b *testing.B) {
29+
for b.Loop() {
30+
cgobench.Callback()
31+
}
32+
}
33+
34+
func BenchmarkCgoCallParallelWithCallback(b *testing.B) {
35+
b.RunParallel(func(pb *testing.PB) {
36+
for pb.Next() {
37+
cgobench.Callback()
38+
}
39+
})
40+
}

src/internal/runtime/cgobench/funcs.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,24 @@ package cgobench
99
/*
1010
static void empty() {
1111
}
12+
13+
void go_empty_callback();
14+
15+
static void callback() {
16+
go_empty_callback();
17+
}
18+
1219
*/
1320
import "C"
1421

1522
func Empty() {
1623
C.empty()
1724
}
25+
26+
func Callback() {
27+
C.callback()
28+
}
29+
30+
//export go_empty_callback
31+
func go_empty_callback() {
32+
}

0 commit comments

Comments
 (0)