From 73a4e109cb0b6957781619ead9abc10dd961ca37 Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Sun, 4 Mar 2012 14:01:23 -0800 Subject: [PATCH] go.crypto/ssh: add benchmarks for marshal and unmarshal R=agl CC=golang-dev https://golang.org/cl/5730045 --- ssh/messages_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ssh/messages_test.go b/ssh/messages_test.go index fe4c397..24a8bd9 100644 --- a/ssh/messages_test.go +++ b/ssh/messages_test.go @@ -123,3 +123,37 @@ func (*kexDHInitMsg) Generate(rand *rand.Rand, size int) reflect.Value { dhi.X = randomInt(rand) return reflect.ValueOf(dhi) } + +var ( + _kexInitMsg = new(kexInitMsg).Generate(rand.New(rand.NewSource(0)), 10).Elem().Interface() + _kexDHInitMsg = new(kexDHInitMsg).Generate(rand.New(rand.NewSource(0)), 10).Elem().Interface() + + _kexInit = marshal(msgKexInit, _kexInitMsg) + _kexDHInit = marshal(msgKexDHInit, _kexDHInitMsg) +) + +func BenchmarkMarshalKexInitMsg(b *testing.B) { + for i := 0; i < b.N; i++ { + marshal(msgKexInit, _kexInitMsg) + } +} + +func BenchmarkUnmarshalKexInitMsg(b *testing.B) { + m := new(kexInitMsg) + for i := 0; i < b.N; i++ { + unmarshal(m, _kexInit, msgKexInit) + } +} + +func BenchmarkMarshalKexDHInitMsg(b *testing.B) { + for i := 0; i < b.N; i++ { + marshal(msgKexDHInit, _kexDHInitMsg) + } +} + +func BenchmarkUnmarshalKexDHInitMsg(b *testing.B) { + m := new(kexDHInitMsg) + for i := 0; i < b.N; i++ { + unmarshal(m, _kexDHInit, msgKexDHInit) + } +}