diff --git a/Makefile b/Makefile index 455bfce..12cd46a 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,10 @@ results: @echo "Create results folder..." @mkdir results -calls: results +calls/func.plugin.so: calls/plugin/nop.go + @go build -buildmode=plugin -o $@ $< + +calls: results calls/func.plugin.so @rm -rf ./results/calls.* @go test ./calls -benchmem -bench=. | tee ./results/calls.log diff --git a/calls/call_test.go b/calls/call_test.go index 97efc24..b0e6703 100644 --- a/calls/call_test.go +++ b/calls/call_test.go @@ -1,11 +1,28 @@ package calls import ( + "plugin" "testing" "github.com/kellabyte/go-benchmarks/calls/asm" ) +var pluginNop func() + +func init() { + plug, err := plugin.Open("func.plugin.so") + if err != nil { + panic(err) + } + + symNop, err := plug.Lookup("Nop") + if err != nil { + panic(err) + } + + pluginNop = symNop.(func()) +} + func BenchmarkCGO(b *testing.B) { for i := 0; i < b.N; i++ { CNop() @@ -20,6 +37,13 @@ func BenchmarkGo(b *testing.B) { } } +func BenchmarkPlugin(b *testing.B) { + for i := 0; i < b.N; i++ { + pluginNop() + b.SetBytes(1) + } +} + func BenchmarkAsm(b *testing.B) { for i := 0; i < b.N; i++ { asm.Nop() diff --git a/calls/plugin/nop.go b/calls/plugin/nop.go new file mode 100644 index 0000000..223ae47 --- /dev/null +++ b/calls/plugin/nop.go @@ -0,0 +1,7 @@ +package main + +func Nop() {} + +func main() { + +}