mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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 <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
b24aec598b
commit
710abf74da
2 changed files with 24 additions and 6 deletions
|
|
@ -11,30 +11,44 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkCgoCall(b *testing.B) {
|
||||
func BenchmarkCall(b *testing.B) {
|
||||
for b.Loop() {
|
||||
cgobench.Empty()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCallParallel(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
cgobench.Empty()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkCgoCall(b *testing.B) {
|
||||
for b.Loop() {
|
||||
cgobench.EmptyC()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCgoCallParallel(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
cgobench.Empty()
|
||||
cgobench.EmptyC()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkCgoCallWithCallback(b *testing.B) {
|
||||
for b.Loop() {
|
||||
cgobench.Callback()
|
||||
cgobench.CallbackC()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCgoCallParallelWithCallback(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
cgobench.Callback()
|
||||
cgobench.CallbackC()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,14 +19,18 @@ static void callback() {
|
|||
*/
|
||||
import "C"
|
||||
|
||||
func Empty() {
|
||||
func EmptyC() {
|
||||
C.empty()
|
||||
}
|
||||
|
||||
func Callback() {
|
||||
func CallbackC() {
|
||||
C.callback()
|
||||
}
|
||||
|
||||
//export go_empty_callback
|
||||
func go_empty_callback() {
|
||||
}
|
||||
|
||||
//go:noinline
|
||||
func Empty() {
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue