Skip to content

Commit 82d4d5e

Browse files
committed
add benchmark for packing&unpacking connect and submit req pkt
1 parent 95f7d67 commit 82d4d5e

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

connect_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,30 @@ func TestCmpp3ConnRspUnpack(t *testing.T) {
275275
}
276276
}
277277
}
278+
279+
func BenchmarkCmppConnReqPktPack(b *testing.B) {
280+
var p = &cmpp.CmppConnReqPkt{
281+
SrcAddr: connSourceAddr,
282+
Version: connVersion,
283+
Secret: connSecret,
284+
Timestamp: connTimestamp,
285+
}
286+
287+
for i := 0; i < b.N; i++ {
288+
p.Pack(seqId)
289+
}
290+
}
291+
292+
func BenchmarkCmppConnReqPktUnpack(b *testing.B) {
293+
data := []byte{
294+
0x00, 0x00, 0x00, 0x17, 0x39, 0x30, 0x30, 0x30,
295+
0x30, 0x31, 0x90, 0xd0, 0x0c, 0x1d, 0x51, 0x7a, 0xbd, 0x0b, 0x4f, 0x65, 0xf6, 0xbc, 0xf8, 0x53,
296+
0x5d, 0x16, 0x21, 0x3c, 0xdc, 0x73, 0xbe,
297+
}
298+
299+
p := &cmpp.CmppConnReqPkt{}
300+
301+
for i := 0; i < b.N; i++ {
302+
p.Unpack(data)
303+
}
304+
}

submit_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,53 @@ func TestCmpp3SubmitRspPktUnpack(t *testing.T) {
409409
t.Fatalf("After unpack, result in packet is %d, not equal to the expected value: %d\n", p.Result, 0)
410410
}
411411
}
412+
413+
func BenchmarkCmpp2SubmitReqPktPack(b *testing.B) {
414+
p := &cmpp.Cmpp2SubmitReqPkt{
415+
PkTotal: pkTotal,
416+
PkNumber: pkNumber,
417+
RegisteredDelivery: registeredDelivery,
418+
MsgLevel: msgLevel,
419+
ServiceId: serviceId,
420+
FeeUserType: feeUserType,
421+
FeeTerminalId: feeTerminalId,
422+
MsgFmt: msgFmt,
423+
MsgSrc: msgSrc,
424+
FeeType: feeType,
425+
FeeCode: feeCode,
426+
ValidTime: validTime,
427+
AtTime: atTime,
428+
SrcId: srcId,
429+
DestUsrTl: destUsrTl,
430+
DestTerminalId: destTerminalId,
431+
MsgLength: msgLength,
432+
MsgContent: msgContent,
433+
}
434+
435+
for i := 0; i < b.N; i++ {
436+
p.Pack(seqId)
437+
}
438+
}
439+
440+
func BenchmarkCmpp2SubmitReqPktUnpack(b *testing.B) {
441+
data := []byte{
442+
0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00,
443+
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x74, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00,
444+
0x00, 0x00, 0x02, 0x31, 0x33, 0x35, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x39, 0x36, 0x00, 0x00,
445+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x39, 0x30, 0x30, 0x30, 0x30,
446+
0x31, 0x30, 0x32, 0x31, 0x30, 0x00, 0x00, 0x00, 0x00, 0x31, 0x35, 0x31, 0x31, 0x30, 0x35, 0x31,
447+
0x33, 0x31, 0x35, 0x35, 0x35, 0x31, 0x30, 0x31, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
448+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x30, 0x30, 0x30, 0x30,
449+
0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
450+
0x01, 0x31, 0x33, 0x35, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x39, 0x36, 0x00, 0x00, 0x00, 0x00,
451+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x6d, 0x4b, 0x8b, 0xd5, 0x00, 0x67, 0x00, 0x6f, 0x00,
452+
0x63, 0x00, 0x6d, 0x00, 0x70, 0x00, 0x70, 0x00, 0x20, 0x00, 0x73, 0x00, 0x75, 0x00, 0x62, 0x00,
453+
0x6d, 0x00, 0x69, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
454+
}
455+
456+
p := &cmpp.Cmpp2SubmitReqPkt{}
457+
458+
for i := 0; i < b.N; i++ {
459+
p.Unpack(data)
460+
}
461+
}

0 commit comments

Comments
 (0)