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
This commit is contained in:
parent
a2eaa5e3d1
commit
6a0206897c
@ -208,3 +208,24 @@ func randBytes(n int) []byte {
|
|||||||
}
|
}
|
||||||
return b
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -108,3 +108,9 @@ func openSSLOpen(a *stupidAEADCommon, dst, iv, in, authData []byte) ([]byte, err
|
|||||||
}
|
}
|
||||||
return append(dst, buf...), nil
|
return append(dst, buf...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This functions exists to benchmark the C call overhead from Go.
|
||||||
|
// See BenchmarkCCall for resuts.
|
||||||
|
func noopCFunction() {
|
||||||
|
C.noop_c_function()
|
||||||
|
}
|
||||||
|
@ -176,3 +176,8 @@ int openssl_aead_open(
|
|||||||
|
|
||||||
return plaintextLen;
|
return plaintextLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This functions exists to benchmark the C call overhead from Go.
|
||||||
|
void noop_c_function(void) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
@ -27,3 +27,5 @@ int openssl_aead_open(
|
|||||||
const int ivLen,
|
const int ivLen,
|
||||||
unsigned char* const plaintext,
|
unsigned char* const plaintext,
|
||||||
const int plaintextBufLen);
|
const int plaintextBufLen);
|
||||||
|
|
||||||
|
void noop_c_function(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user