This commit is contained in:
Jae Kwon
2014-07-08 22:39:36 -07:00
parent dca79ab5c1
commit ed19b7e0ae
2 changed files with 33 additions and 50 deletions

View File

@ -108,38 +108,6 @@ func BenchmarkTestGob(b *testing.B) {
func BenchmarkTestMsgPack(b *testing.B) {
b.StopTimer()
var mh codec.MsgpackHandle
handle := &mh
h := &Header{
Name: "Header",
Height: 123,
Fees: 123,
Time: 123,
PrevHash: []byte("prevhash"),
ValidationHash: []byte("validationhash"),
DataHash: []byte("datahash"),
}
h2 := &Header{}
buf := bytes.NewBuffer(nil)
enc := codec.NewEncoder(buf, handle)
dec := codec.NewDecoder(buf, handle)
b.StartTimer()
for i := 0; i < b.N; i++ {
buf.Reset()
enc.Encode(h)
dec.Decode(h2)
if h2.Name != "Header" {
b.Fatalf("wrong name")
}
}
}
func BenchmarkTestMsgPack2(b *testing.B) {
b.StopTimer()
h := &Header{
Name: "Header",
Height: 123,
@ -165,3 +133,34 @@ func BenchmarkTestMsgPack2(b *testing.B) {
}
}
}
func BenchmarkTestMsgPack2(b *testing.B) {
b.StopTimer()
h := &Header{
Name: "Header",
Height: 123,
Fees: 123,
Time: 123,
PrevHash: []byte("prevhash"),
ValidationHash: []byte("validationhash"),
DataHash: []byte("datahash"),
}
h2 := &Header{}
var mh codec.MsgpackHandle
handle := &mh
buf := bytes.NewBuffer(nil)
enc := codec.NewEncoder(buf, handle)
dec := codec.NewDecoder(buf, handle)
b.StartTimer()
for i := 0; i < b.N; i++ {
buf.Reset()
enc.Encode(h)
dec.Decode(h2)
if h2.Name != "Header" {
b.Fatalf("wrong name")
}
}
}