summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2023-03-08 16:54:56 +0100
committerJakob Unterwurzacher2023-03-08 16:54:56 +0100
commitd74cf7c72337e7b6d4c57d357e855b19fe1f5c9a (patch)
tree1b4faf0ec288ee134c858d98b3ce1036961bb876
parent77a0410e2ed77cae279bf7a1bcbfff82dbf56e16 (diff)
speed: add per-blocksize GoGCM benchmarks
Only visible when you run "go test -bench" like this: $ cd gocryptfs/internal/speed $ go test -bench . goos: linux goarch: amd64 pkg: github.com/rfjakob/gocryptfs/v2/internal/speed cpu: Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz BenchmarkStupidGCM-4 202352 5937 ns/op 689.96 MB/s BenchmarkStupidGCMDecrypt-4 206023 5782 ns/op 708.38 MB/s BenchmarkGoGCM-4 291878 4098 ns/op 999.45 MB/s BenchmarkGoGCMBlockSize/1024-4 1000000 1151 ns/op 889.88 MB/s BenchmarkGoGCMBlockSize/2048-4 561182 2134 ns/op 959.60 MB/s BenchmarkGoGCMBlockSize/4096-4 292057 4101 ns/op 998.87 MB/s BenchmarkGoGCMBlockSize/8192-4 149216 8031 ns/op 1020.09 MB/s BenchmarkGoGCMBlockSize/16384-4 75361 15917 ns/op 1029.34 MB/s BenchmarkGoGCMBlockSize/32768-4 37916 31649 ns/op 1035.35 MB/s BenchmarkGoGCMBlockSize/65536-4 19005 63117 ns/op 1038.33 MB/s BenchmarkGoGCMBlockSize/131072-4 9498 126166 ns/op 1038.89 MB/s BenchmarkGoGCMBlockSize/262144-4 4755 252149 ns/op 1039.64 MB/s BenchmarkGoGCMBlockSize/524288-4 2377 504108 ns/op 1040.03 MB/s BenchmarkGoGCMBlockSize/1048576-4 1188 1008675 ns/op 1039.56 MB/s BenchmarkGoGCMDecrypt-4 294664 4059 ns/op 1009.02 MB/s BenchmarkAESSIV-4 46498 25432 ns/op 161.05 MB/s BenchmarkAESSIVDecrypt-4 46908 25509 ns/op 160.57 MB/s BenchmarkXchacha-4 244473 4894 ns/op 836.97 MB/s BenchmarkXchachaDecrypt-4 249710 4798 ns/op 853.75 MB/s BenchmarkStupidXchacha-4 166988 7101 ns/op 576.79 MB/s BenchmarkStupidXchachaDecrypt-4 163093 7240 ns/op 565.72 MB/s BenchmarkStupidChacha-4 184172 6527 ns/op 627.58 MB/s BenchmarkStupidChachaDecrypt-4 179796 6659 ns/op 615.11 MB/s PASS ok github.com/rfjakob/gocryptfs/v2/internal/speed 30.068s
-rw-r--r--internal/speed/speed.go16
-rw-r--r--internal/speed/speed_test.go8
2 files changed, 20 insertions, 4 deletions
diff --git a/internal/speed/speed.go b/internal/speed/speed.go
index 950bbda..47fe8c9 100644
--- a/internal/speed/speed.go
+++ b/internal/speed/speed.go
@@ -23,7 +23,7 @@ import (
const adLen = 24
// gocryptfs uses fixed-size 4 kiB blocks
-const blockSize = 4096
+const gocryptfsBlockSize = 4096
// Run - run the speed the test and print the results.
func Run() {
@@ -83,6 +83,11 @@ func randBytes(n int) []byte {
// bEncrypt benchmarks the encryption speed of cipher "c"
func bEncrypt(b *testing.B, c cipher.AEAD) {
+ bEncryptBlockSize(b, c, gocryptfsBlockSize)
+}
+
+// bEncryptBlockSize benchmarks the encryption speed of cipher "c" at block size "blockSize"
+func bEncryptBlockSize(b *testing.B, c cipher.AEAD, blockSize int) {
authData := randBytes(adLen)
iv := randBytes(c.NonceSize())
in := make([]byte, blockSize)
@@ -97,13 +102,12 @@ func bEncrypt(b *testing.B, c cipher.AEAD) {
// Encrypt and append to nonce
c.Seal(dst, iv, in, authData)
}
-
}
func bDecrypt(b *testing.B, c cipher.AEAD) {
authData := randBytes(adLen)
iv := randBytes(c.NonceSize())
- plain := randBytes(blockSize)
+ plain := randBytes(gocryptfsBlockSize)
ciphertext := c.Seal(iv, iv, plain, authData)
b.SetBytes(int64(len(plain)))
@@ -129,6 +133,10 @@ func bStupidGCM(b *testing.B) {
// bGoGCM benchmarks Go stdlib GCM
func bGoGCM(b *testing.B) {
+ bGoGCMBlockSize(b, gocryptfsBlockSize)
+}
+
+func bGoGCMBlockSize(b *testing.B, blockSize int) {
gAES, err := aes.NewCipher(randBytes(32))
if err != nil {
b.Fatal(err)
@@ -137,7 +145,7 @@ func bGoGCM(b *testing.B) {
if err != nil {
b.Fatal(err)
}
- bEncrypt(b, gGCM)
+ bEncryptBlockSize(b, gGCM, blockSize)
}
// bAESSIV benchmarks AES-SIV from github.com/aperturerobotics/jacobsa-crypto/siv
diff --git a/internal/speed/speed_test.go b/internal/speed/speed_test.go
index 5f3001b..39ef918 100644
--- a/internal/speed/speed_test.go
+++ b/internal/speed/speed_test.go
@@ -3,6 +3,7 @@ package speed
import (
"crypto/aes"
"crypto/cipher"
+ "fmt"
"testing"
"golang.org/x/crypto/chacha20poly1305"
@@ -38,6 +39,13 @@ func BenchmarkGoGCM(b *testing.B) {
bGoGCM(b)
}
+func BenchmarkGoGCMBlockSize(b *testing.B) {
+ for blockSize := 1024; blockSize <= 1024*1024; blockSize *= 2 {
+ name := fmt.Sprintf("%d", blockSize)
+ b.Run(name, func(b *testing.B) { bGoGCMBlockSize(b, blockSize) })
+ }
+}
+
func BenchmarkGoGCMDecrypt(b *testing.B) {
gAES, err := aes.NewCipher(randBytes(32))
if err != nil {