aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/kylelemons/gousb/usb/libusb_cgo_benchmark_test.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-09-09 09:42:37 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-09-09 09:42:37 +0200
commit500caaeda74dd9c660279036293f4b2997cf0b03 (patch)
tree1226f60231a408b0aae67867faaa3f2cfbac8c83 /vendor/github.com/kylelemons/gousb/usb/libusb_cgo_benchmark_test.go
parent413560591fc2d89a73eb8a33ba28b0cc3407b1db (diff)
Add vendor
Diffstat (limited to 'vendor/github.com/kylelemons/gousb/usb/libusb_cgo_benchmark_test.go')
-rw-r--r--vendor/github.com/kylelemons/gousb/usb/libusb_cgo_benchmark_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/github.com/kylelemons/gousb/usb/libusb_cgo_benchmark_test.go b/vendor/github.com/kylelemons/gousb/usb/libusb_cgo_benchmark_test.go
new file mode 100644
index 0000000..da8acc9
--- /dev/null
+++ b/vendor/github.com/kylelemons/gousb/usb/libusb_cgo_benchmark_test.go
@@ -0,0 +1,46 @@
+package usb
+
+import "testing"
+
+func BenchmarkCGo(b *testing.B) {
+ for _, bc := range []struct {
+ name string
+ bfunc func(*libusbContext, int)
+ }{
+ {
+ name: "simple function",
+ bfunc: func(ctx *libusbContext, N int) {
+ for i := 0; i < N; i++ {
+ libusbSetDebug(ctx, i&1)
+ }
+ },
+ },
+ {
+ name: "method",
+ bfunc: func(ctx *libusbContext, N int) {
+ impl := libusbImpl{}
+ for i := 0; i < N; i++ {
+ impl.setDebug(ctx, i&1)
+ }
+ },
+ },
+ {
+ name: "interface",
+ bfunc: func(ctx *libusbContext, N int) {
+ var intf libusbIntf = libusbImpl{}
+ for i := 0; i < N; i++ {
+ intf.setDebug(ctx, i&1)
+ }
+ },
+ },
+ } {
+ b.Run(bc.name, func(b *testing.B) {
+ ctx, err := libusbImpl{}.init()
+ if err != nil {
+ b.Fatalf("libusb_init() failed: %v", err)
+ }
+ b.ResetTimer()
+ bc.bfunc(ctx, b.N)
+ })
+ }
+}