From cf1f044251ea6e6c999566871a9f4b2a3d627d20 Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Fri, 6 Apr 2012 04:19:35 +0800 Subject: [PATCH] crypto/aes: add benchmarks for decryption and key expansion R=agl, rsc, fullung CC=golang-dev https://golang.org/cl/5972056 --- src/pkg/crypto/aes/aes_test.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/pkg/crypto/aes/aes_test.go b/src/pkg/crypto/aes/aes_test.go index e500c666d9..c30ccf3f18 100644 --- a/src/pkg/crypto/aes/aes_test.go +++ b/src/pkg/crypto/aes/aes_test.go @@ -352,15 +352,39 @@ func TestCipherDecrypt(t *testing.T) { } func BenchmarkEncrypt(b *testing.B) { - b.StopTimer() tt := encryptTests[0] c, err := NewCipher(tt.key) if err != nil { b.Fatal("NewCipher:", err) } out := make([]byte, len(tt.in)) - b.StartTimer() + b.SetBytes(int64(len(out))) + b.ResetTimer() for i := 0; i < b.N; i++ { c.Encrypt(out, tt.in) } } + +func BenchmarkDecrypt(b *testing.B) { + tt := encryptTests[0] + c, err := NewCipher(tt.key) + if err != nil { + b.Fatal("NewCipher:", err) + } + out := make([]byte, len(tt.out)) + b.SetBytes(int64(len(out))) + b.ResetTimer() + for i := 0; i < b.N; i++ { + c.Decrypt(out, tt.out) + } +} + +func BenchmarkExpand(b *testing.B) { + tt := encryptTests[0] + n := len(tt.key) + 28 + c := &aesCipher{make([]uint32, n), make([]uint32, n)} + b.ResetTimer() + for i := 0; i < b.N; i++ { + expandKey(tt.key, c.enc, c.dec) + } +} -- 2.48.1