]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/aes: add benchmarks for decryption and key expansion
authorShenghou Ma <minux.ma@gmail.com>
Thu, 5 Apr 2012 20:19:35 +0000 (04:19 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Thu, 5 Apr 2012 20:19:35 +0000 (04:19 +0800)
R=agl, rsc, fullung
CC=golang-dev
https://golang.org/cl/5972056

src/pkg/crypto/aes/aes_test.go

index e500c666d97ee42b62e4a6cc20d0343068ed649d..c30ccf3f18757c33b65bfbaf8087624fcdeb7a63 100644 (file)
@@ -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)
+       }
+}