libgocryptfs/internal/speed/speed_test.go
Jakob Unterwurzacher a2eaa5e3d1 speed: add BenchmarkStupidChacha
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              	  249396	      4722 ns/op	 867.50 MB/s
BenchmarkStupidGCMDecrypt-4       	  257872	      4616 ns/op	 887.35 MB/s
BenchmarkGoGCM-4                  	  290952	      4097 ns/op	 999.83 MB/s
BenchmarkGoGCMDecrypt-4           	  294106	      4060 ns/op	1008.84 MB/s
BenchmarkAESSIV-4                 	   46520	     25532 ns/op	 160.42 MB/s
BenchmarkAESSIVDecrypt-4          	   46974	     25478 ns/op	 160.76 MB/s
BenchmarkXchacha-4                	  244108	      4881 ns/op	 839.14 MB/s
BenchmarkXchachaDecrypt-4         	  249658	      4786 ns/op	 855.86 MB/s
BenchmarkStupidXchacha-4          	  205339	      5768 ns/op	 710.11 MB/s
BenchmarkStupidXchachaDecrypt-4   	  204577	      5836 ns/op	 701.84 MB/s
BenchmarkStupidChacha-4           	  227510	      5224 ns/op	 784.06 MB/s
BenchmarkStupidChachaDecrypt-4    	  222787	      5359 ns/op	 764.34 MB/s
PASS
ok  	github.com/rfjakob/gocryptfs/v2/internal/speed	15.328s
2021-09-07 18:14:05 +02:00

85 lines
1.8 KiB
Go

package speed
import (
"crypto/aes"
"crypto/cipher"
"testing"
"golang.org/x/crypto/chacha20poly1305"
"github.com/rfjakob/gocryptfs/v2/internal/siv_aead"
"github.com/rfjakob/gocryptfs/v2/internal/stupidgcm"
)
/*
Make the "-speed" benchmarks also accessible to the standard test system.
Example run:
$ go test -bench .
BenchmarkStupidGCM-2 100000 22552 ns/op 181.62 MB/s
BenchmarkGoGCM-2 20000 81871 ns/op 50.03 MB/s
BenchmarkAESSIV-2 10000 104623 ns/op 39.15 MB/s
PASS
ok github.com/rfjakob/gocryptfs/v2/internal/speed 6.022s
*/
func BenchmarkStupidGCM(b *testing.B) {
bStupidGCM(b)
}
func BenchmarkStupidGCMDecrypt(b *testing.B) {
if stupidgcm.BuiltWithoutOpenssl {
b.Skip("openssl has been disabled at compile-time")
}
bDecrypt(b, stupidgcm.New(randBytes(32), false))
}
func BenchmarkGoGCM(b *testing.B) {
bGoGCM(b)
}
func BenchmarkGoGCMDecrypt(b *testing.B) {
gAES, err := aes.NewCipher(randBytes(32))
if err != nil {
b.Fatal(err)
}
gGCM, err := cipher.NewGCMWithNonceSize(gAES, 16)
if err != nil {
b.Fatal(err)
}
bDecrypt(b, gGCM)
}
func BenchmarkAESSIV(b *testing.B) {
bAESSIV(b)
}
func BenchmarkAESSIVDecrypt(b *testing.B) {
bEncrypt(b, siv_aead.New(randBytes(64)))
}
func BenchmarkXchacha(b *testing.B) {
bXchacha20poly1305(b)
}
func BenchmarkXchachaDecrypt(b *testing.B) {
c, _ := chacha20poly1305.NewX(randBytes(32))
bDecrypt(b, c)
}
func BenchmarkStupidXchacha(b *testing.B) {
bStupidXchacha(b)
}
func BenchmarkStupidXchachaDecrypt(b *testing.B) {
bDecrypt(b, stupidgcm.NewXchacha20poly1305(randBytes(32)))
}
func BenchmarkStupidChacha(b *testing.B) {
bEncrypt(b, stupidgcm.NewChacha20poly1305(randBytes(32)))
}
func BenchmarkStupidChachaDecrypt(b *testing.B) {
bDecrypt(b, stupidgcm.NewChacha20poly1305(randBytes(32)))
}