Add encrypt benchmark

This commit is contained in:
Jonathan Rudenberg 2014-07-03 21:26:45 -07:00
parent f585254b83
commit 8a2dc23c1f
No known key found for this signature in database
GPG Key ID: E38D8C6BAA8C49AA
1 changed files with 31 additions and 16 deletions

View File

@ -14,22 +14,7 @@ type S struct{}
var _ = Suite(&S{})
func (s *S) TestRoundtrip(c *C) {
recvKey, _ := Noise255.GenerateKey(rand.Reader)
sendKey, _ := Noise255.GenerateKey(rand.Reader)
enc := &Crypter{
Cipher: Noise255,
SenderKey: sendKey,
ReceiverKey: recvKey,
}
enc.ReceiverKey.Private = nil
dec := &Crypter{
Cipher: Noise255,
SenderKey: sendKey,
ReceiverKey: recvKey,
}
dec.SenderKey.Private = nil
enc, dec := newCrypters()
plain := []byte("yellow submarines")
padLen := 2
@ -51,3 +36,33 @@ func (s *S) TestRoundtrip(c *C) {
c.Assert(err, IsNil)
c.Assert(plaintext, DeepEquals, plain)
}
func newCrypters() (*Crypter, *Crypter) {
recvKey, _ := Noise255.GenerateKey(rand.Reader)
sendKey, _ := Noise255.GenerateKey(rand.Reader)
enc := &Crypter{
Cipher: Noise255,
SenderKey: sendKey,
ReceiverKey: recvKey,
}
enc.ReceiverKey.Private = nil
dec := &Crypter{
Cipher: Noise255,
SenderKey: sendKey,
ReceiverKey: recvKey,
}
dec.SenderKey.Private = nil
return enc, dec
}
func BenchmarkEncrypt(b *testing.B) {
enc, _ := newCrypters()
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
enc.Encrypt(nil, nil, []byte("yellow submarine"), 0)
}
}