Skip to content

Instantly share code, notes, and snippets.

@dylanahsmith
Created July 7, 2021 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanahsmith/d4905edc8e0c31161835064525b6205d to your computer and use it in GitHub Desktop.
Save dylanahsmith/d4905edc8e0c31161835064525b6205d to your computer and use it in GitHub Desktop.
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkGoToGoCall-12 1000000000 0.2525 ns/op
BenchmarkGoToCCall-12 22471992 53.89 ns/op
BenchmarkCToGoCall-12 8209108 148.8 ns/op
#include <stdint.h>
void call() {
}
void goCallback();
void callCallback() {
goCallback();
}
package helper
// #include <stdint.h>
// void call();
// void callCallback();
import "C"
import (
"runtime"
)
func GoCall(v interface{}) {
runtime.KeepAlive(v)
}
func CCall() {
C.call()
}
//export goCallback
func goCallback() {
}
func GoCallback() {
C.callCallback()
}
package helper
import (
"testing"
)
func BenchmarkGoToGoCall(b *testing.B) {
for i := 0; i < b.N; i++ {
GoCall(i)
}
}
func BenchmarkGoToCCall(b *testing.B) {
for i := 0; i < b.N; i++ {
CCall()
}
}
func BenchmarkCToGoCall(b *testing.B) {
for i := 0; i < b.N; i++ {
GoCallback()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment