aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/crypto/cipher/benchmark_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2021-07-30 14:28:58 -0700
committerIan Lance Taylor <iant@golang.org>2021-08-12 20:23:07 -0700
commitc5b21c3f4c17b0649155035d2f9aa97b2da8a813 (patch)
treec6d3a68b503ba5b16182acbb958e3e5dbc95a43b /libgo/go/crypto/cipher/benchmark_test.go
parent72be20e20299ec57b4bc9ba03d5b7d6bf10e97cc (diff)
downloadgcc-c5b21c3f4c17b0649155035d2f9aa97b2da8a813.zip
gcc-c5b21c3f4c17b0649155035d2f9aa97b2da8a813.tar.gz
gcc-c5b21c3f4c17b0649155035d2f9aa97b2da8a813.tar.bz2
libgo: update to Go1.17rc2
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/341629
Diffstat (limited to 'libgo/go/crypto/cipher/benchmark_test.go')
-rw-r--r--libgo/go/crypto/cipher/benchmark_test.go68
1 files changed, 26 insertions, 42 deletions
diff --git a/libgo/go/crypto/cipher/benchmark_test.go b/libgo/go/crypto/cipher/benchmark_test.go
index 90d0cd7..eb02cd0 100644
--- a/libgo/go/crypto/cipher/benchmark_test.go
+++ b/libgo/go/crypto/cipher/benchmark_test.go
@@ -7,28 +7,15 @@ package cipher_test
import (
"crypto/aes"
"crypto/cipher"
+ "strconv"
"testing"
)
-func benchmarkAESGCMSign(b *testing.B, buf []byte) {
+func benchmarkAESGCMSeal(b *testing.B, buf []byte, keySize int) {
+ b.ReportAllocs()
b.SetBytes(int64(len(buf)))
- var key [16]byte
- var nonce [12]byte
- aes, _ := aes.NewCipher(key[:])
- aesgcm, _ := cipher.NewGCM(aes)
- var out []byte
-
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- out = aesgcm.Seal(out[:0], nonce[:], nil, buf)
- }
-}
-
-func benchmarkAESGCMSeal(b *testing.B, buf []byte) {
- b.SetBytes(int64(len(buf)))
-
- var key [16]byte
+ var key = make([]byte, keySize)
var nonce [12]byte
var ad [13]byte
aes, _ := aes.NewCipher(key[:])
@@ -41,44 +28,41 @@ func benchmarkAESGCMSeal(b *testing.B, buf []byte) {
}
}
-func benchmarkAESGCMOpen(b *testing.B, buf []byte) {
+func benchmarkAESGCMOpen(b *testing.B, buf []byte, keySize int) {
+ b.ReportAllocs()
b.SetBytes(int64(len(buf)))
- var key [16]byte
+ var key = make([]byte, keySize)
var nonce [12]byte
var ad [13]byte
aes, _ := aes.NewCipher(key[:])
aesgcm, _ := cipher.NewGCM(aes)
var out []byte
- out = aesgcm.Seal(out[:0], nonce[:], buf, ad[:])
+
+ ct := aesgcm.Seal(nil, nonce[:], buf[:], ad[:])
b.ResetTimer()
for i := 0; i < b.N; i++ {
- _, err := aesgcm.Open(buf[:0], nonce[:], out, ad[:])
- if err != nil {
- b.Errorf("Open: %v", err)
- }
+ out, _ = aesgcm.Open(out[:0], nonce[:], ct, ad[:])
}
}
-func BenchmarkAESGCMSeal1K(b *testing.B) {
- benchmarkAESGCMSeal(b, make([]byte, 1024))
-}
-
-func BenchmarkAESGCMOpen1K(b *testing.B) {
- benchmarkAESGCMOpen(b, make([]byte, 1024))
-}
-
-func BenchmarkAESGCMSign8K(b *testing.B) {
- benchmarkAESGCMSign(b, make([]byte, 8*1024))
-}
-
-func BenchmarkAESGCMSeal8K(b *testing.B) {
- benchmarkAESGCMSeal(b, make([]byte, 8*1024))
-}
-
-func BenchmarkAESGCMOpen8K(b *testing.B) {
- benchmarkAESGCMOpen(b, make([]byte, 8*1024))
+func BenchmarkAESGCM(b *testing.B) {
+ for _, length := range []int{64, 1350, 8 * 1024} {
+ b.Run("Open-128-"+strconv.Itoa(length), func(b *testing.B) {
+ benchmarkAESGCMOpen(b, make([]byte, length), 128/8)
+ })
+ b.Run("Seal-128-"+strconv.Itoa(length), func(b *testing.B) {
+ benchmarkAESGCMSeal(b, make([]byte, length), 128/8)
+ })
+
+ b.Run("Open-256-"+strconv.Itoa(length), func(b *testing.B) {
+ benchmarkAESGCMOpen(b, make([]byte, length), 256/8)
+ })
+ b.Run("Seal-256-"+strconv.Itoa(length), func(b *testing.B) {
+ benchmarkAESGCMSeal(b, make([]byte, length), 256/8)
+ })
+ }
}
func benchmarkAESStream(b *testing.B, mode func(cipher.Block, []byte) cipher.Stream, buf []byte) {