diff options
Diffstat (limited to 'src/crypto/cipher/benchmark_test.go')
| -rw-r--r-- | src/crypto/cipher/benchmark_test.go | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/crypto/cipher/benchmark_test.go b/src/crypto/cipher/benchmark_test.go index 027b248510..93c40d0f46 100644 --- a/src/crypto/cipher/benchmark_test.go +++ b/src/crypto/cipher/benchmark_test.go @@ -10,42 +10,58 @@ import ( "testing" ) -func BenchmarkAESGCMSeal1K(b *testing.B) { - buf := make([]byte, 1024) +func benchmarkAESGCMSeal(b *testing.B, buf []byte) { b.SetBytes(int64(len(buf))) var key [16]byte var nonce [12]byte + var ad [13]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[:], buf, nonce[:]) + out = aesgcm.Seal(out[:0], nonce[:], buf, ad[:]) } } -func BenchmarkAESGCMOpen1K(b *testing.B) { - buf := make([]byte, 1024) +func benchmarkAESGCMOpen(b *testing.B, buf []byte) { b.SetBytes(int64(len(buf))) var key [16]byte 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, nonce[:]) + out = aesgcm.Seal(out[:0], nonce[:], buf, ad[:]) b.ResetTimer() for i := 0; i < b.N; i++ { - _, err := aesgcm.Open(buf[:0], nonce[:], out, nonce[:]) + _, err := aesgcm.Open(buf[:0], nonce[:], out, ad[:]) if err != nil { b.Errorf("Open: %v", err) } } } +func BenchmarkAESGCMSeal1K(b *testing.B) { + benchmarkAESGCMSeal(b, make([]byte, 1024)) +} + +func BenchmarkAESGCMOpen1K(b *testing.B) { + benchmarkAESGCMOpen(b, make([]byte, 1024)) +} + +func BenchmarkAESGCMSeal8K(b *testing.B) { + benchmarkAESGCMSeal(b, make([]byte, 8*1024)) +} + +func BenchmarkAESGCMOpen8K(b *testing.B) { + benchmarkAESGCMOpen(b, make([]byte, 8*1024)) +} + // If we test exactly 1K blocks, we would generate exact multiples of // the cipher's block size, and the cipher stream fragments would // always be wordsize aligned, whereas non-aligned is a more typical |
