浏览代码

go.crypto/ssh: add benchmarks for marshal and unmarshal

R=agl
CC=golang-dev
https://golang.org/cl/5730045
Dave Cheney 13 年之前
父节点
当前提交
73a4e109cb
共有 1 个文件被更改,包括 34 次插入0 次删除
  1. 34 0
      ssh/messages_test.go

+ 34 - 0
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)
+	}
+}