Created
July 7, 2021 15:57
-
-
Save dylanahsmith/d4905edc8e0c31161835064525b6205d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gist title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
void call() { | |
} | |
void goCallback(); | |
void callCallback() { | |
goCallback(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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