Skip to content

Commit 710abf7

Browse files
mknyszekgopherbot
authored andcommitted
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Michael Knyszek <[email protected]>
1 parent b24aec5 commit 710abf7

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/internal/runtime/cgobench/bench_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,44 @@ import (
1111
"testing"
1212
)
1313

14-
func BenchmarkCgoCall(b *testing.B) {
14+
func BenchmarkCall(b *testing.B) {
1515
for b.Loop() {
1616
cgobench.Empty()
1717
}
1818
}
1919

20-
func BenchmarkCgoCallParallel(b *testing.B) {
20+
func BenchmarkCallParallel(b *testing.B) {
2121
b.RunParallel(func(pb *testing.PB) {
2222
for pb.Next() {
2323
cgobench.Empty()
2424
}
2525
})
2626
}
2727

28+
func BenchmarkCgoCall(b *testing.B) {
29+
for b.Loop() {
30+
cgobench.EmptyC()
31+
}
32+
}
33+
34+
func BenchmarkCgoCallParallel(b *testing.B) {
35+
b.RunParallel(func(pb *testing.PB) {
36+
for pb.Next() {
37+
cgobench.EmptyC()
38+
}
39+
})
40+
}
41+
2842
func BenchmarkCgoCallWithCallback(b *testing.B) {
2943
for b.Loop() {
30-
cgobench.Callback()
44+
cgobench.CallbackC()
3145
}
3246
}
3347

3448
func BenchmarkCgoCallParallelWithCallback(b *testing.B) {
3549
b.RunParallel(func(pb *testing.PB) {
3650
for pb.Next() {
37-
cgobench.Callback()
51+
cgobench.CallbackC()
3852
}
3953
})
4054
}

src/internal/runtime/cgobench/funcs.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ static void callback() {
1919
*/
2020
import "C"
2121

22-
func Empty() {
22+
func EmptyC() {
2323
C.empty()
2424
}
2525

26-
func Callback() {
26+
func CallbackC() {
2727
C.callback()
2828
}
2929

3030
//export go_empty_callback
3131
func go_empty_callback() {
3232
}
33+
34+
//go:noinline
35+
func Empty() {
36+
}

0 commit comments

Comments
 (0)