-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathutils_test.go
58 lines (49 loc) · 1.45 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package ibapi
import (
_ "net/http/pprof"
"testing"
// "time"
)
// func makeMsgBytesOld(fields ...interface{}) []byte {
// // make the whole the slice of msgBytes
// msgBytesSlice := make([][]byte, 0, len(fields))
// for _, f := range fields {
// // make the field into msgBytes
// msgBytes := field2Bytes(f)
// msgBytesSlice = append(msgBytesSlice, msgBytes)
// }
// msg := bytes.Join(msgBytesSlice, nil)
// // add the size header
// sizeBytes := make([]byte, 4, 4+len(msg))
// binary.BigEndian.PutUint32(sizeBytes, uint32(len(msg)))
// return append(sizeBytes, msg...)
// }
// func TestMakeMsgEqual(t *testing.T) {
// var v1 int64 = 19901130
// var v2 float64 = 0.123456
// var v3 string = "bla bla bla"
// var v4 bool = true
// var v5 []byte = []byte("hadrianl")
// var v6 int = 20201130
// oldBytes := makeMsgBytesOld(v3, v1, v2, v3, v4, v5, v6)
// newBytes := makeMsgBytes(v3, v1, v2, v3, v4, v5, v6)
// t.Log("old:", oldBytes)
// t.Log("new:", newBytes)
// if !bytes.Equal(oldBytes, newBytes) {
// t.Fatal("bytes not equal!")
// }
// }
func BenchmarkMakeMsg(b *testing.B) {
// log, _ = zap.NewDevelopment()
var v1 int64 = 19901130
var v2 float64 = 0.123456
var v3 string = "bla bla bla"
var v4 bool = true
var v5 []byte = []byte("hadrianl")
var v6 int = 20201130
// var updateAccountValueMsgBuf = NewMsgBuffer(nil)
for i := 0; i < b.N; i++ {
// updateAccountValueMsgBuf.Write(msgBytes)
makeMsgBytes(v1, v2, v3, v4, v5, v6)
}
}