From 6a0206897c83e1f3e4539d6a6c77149167f49626 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 5 Sep 2021 12:17:38 +0200 Subject: stupidgcm: add BenchmarkCCall gocryptfs/internal/stupidgcm$ go test -bench . goos: linux goarch: amd64 pkg: github.com/rfjakob/gocryptfs/v2/internal/stupidgcm cpu: Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz BenchmarkCCall-4 15864030 78.60 ns/op PASS ok github.com/rfjakob/gocryptfs/v2/internal/stupidgcm 1.898s --- internal/stupidgcm/common_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'internal/stupidgcm/common_test.go') diff --git a/internal/stupidgcm/common_test.go b/internal/stupidgcm/common_test.go index a8080ca..589d974 100644 --- a/internal/stupidgcm/common_test.go +++ b/internal/stupidgcm/common_test.go @@ -208,3 +208,24 @@ func randBytes(n int) []byte { } return b } + +/* +BenchmarkCCall benchmarks the overhead of calling from Go into C. +Looks like things improved a bit compared to +https://www.cockroachlabs.com/blog/the-cost-and-complexity-of-cgo/ +where they measured 171ns/op: + +$ go test -bench . +goos: linux +goarch: amd64 +pkg: github.com/rfjakob/gocryptfs/v2/internal/stupidgcm +cpu: Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz +BenchmarkCCall-4 13989364 76.72 ns/op +PASS +ok github.com/rfjakob/gocryptfs/v2/internal/stupidgcm 1.735s +*/ +func BenchmarkCCall(b *testing.B) { + for i := 0; i < b.N; i++ { + noopCFunction() + } +} -- cgit v1.2.3