Skip to content

Commit

Permalink
Little benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Gajewski committed Nov 10, 2016
1 parent dbd41a0 commit 54803ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,16 @@ Exported functions (3):
- ReturningStringSlice func() ([]string)
- ReturningIntArray func() ([3]int32)
```

## Plugin call overhead

Using `-buildmode=plugin` with generated plugin seems not to add overhead when calling methods on a wrapper.

```go
BenchmarkCallOverhead/plugin-8 30000000 58.0 ns/op 0 B/op 0 allocs/op
BenchmarkCallOverhead/plugin-8 30000000 59.3 ns/op 0 B/op 0 allocs/op
BenchmarkCallOverhead/plugin-8 30000000 54.8 ns/op 0 B/op 0 allocs/op
BenchmarkCallOverhead/native-8 20000000 59.3 ns/op 0 B/op 0 allocs/op
BenchmarkCallOverhead/native-8 20000000 59.8 ns/op 0 B/op 0 allocs/op
BenchmarkCallOverhead/native-8 20000000 59.7 ns/op 0 B/op 0 allocs/op
```
9 changes: 8 additions & 1 deletion cli/cli_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import "testing"
//go:generate go-bind-plugin -plugin-package ../internal/test_fixtures/benchmark_plugin -output-package cli -output-path cli_test_plugin.go -output-name BenchmarkPlugin
func BenchmarkCallOverhead(b *testing.B) {
pl, err := BindBenchmarkPlugin("plugin.so")
numbers := 10000
numbers := 100
sl := prepareLargeSlice(numbers)
expectedSum := uint64(numbers * (numbers + 1) / 2)

if err != nil {
b.Fatalf("Could not setup benchmark: %s", err)
}

b.Log("Running benchmarks...")

b.Run("plugin", func(b *testing.B) {

b.ReportAllocs()

for i := 0; i < b.N; i++ {
sum := pl.Sum(sl)

Expand All @@ -26,6 +30,9 @@ func BenchmarkCallOverhead(b *testing.B) {
})

b.Run("native", func(b *testing.B) {

b.ReportAllocs()

for i := 0; i < b.N; i++ {
sum := nativeSum(sl)

Expand Down

0 comments on commit 54803ea

Please sign in to comment.