From 2692b5df0d899b4960072dbbab5432606daac586 Mon Sep 17 00:00:00 2001 From: Justine Alexandra Roberts Tunney Date: Sat, 11 Apr 2015 15:19:04 -0400 Subject: [PATCH] Benchmarks. --- sip/msg_test.go | 81 ++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/sip/msg_test.go b/sip/msg_test.go index e77c212..e1e6495 100755 --- a/sip/msg_test.go +++ b/sip/msg_test.go @@ -6,6 +6,40 @@ import ( "testing" ) +const ( + torture2 = "!interesting-Method0123456789_*+`.%indeed'~ sip:1_unusual.URI~(to-be!sure)&isn't+it$/crazy?,/;;*:&it+has=1,weird!*pas$wo~d_too.(doesn't-it)@example.com SIP/2.0\r\n" + + "Via: SIP/2.0/TCP host1.example.com;branch=z9hG4bK-.!%66*_+`'~\r\n" + + "To: \"BEL:\\\x07 NUL:\\\x00 DEL:\\\x7F\" \r\n" + + "From: token1~` token2'+_ token3*%!.- ;fromParam''~+*_!.-%=\"\xD1\x80\xD0\xB0\xD0\xB1\xD0\xBE\xD1\x82\xD0\xB0\xD1\x8E\xD1\x89\xD0\xB8\xD0\xB9\";tag=_token~1'+`*%!-.\r\n" + + "Call-ID: intmeth.word%ZK-!.*_+'@word`~)(><:\\/\"][?}{\r\n" + + "CSeq: 139122385 !interesting-Method0123456789_*+`.%indeed'~\r\n" + + "Max-Forwards: 255\r\n" + + "extensionHeader-!.%*+_`'~:\xEF\xBB\xBF\xE5\xA4\xA7\xE5\x81\x9C\xE9\x9B\xBB\r\n" + + "Content-Length: 0\r\n" + + "\r\n" + flowroute = "SIP/2.0 200 OK\r\n" + + "Via: SIP/2.0/UDP 1.2.3.4:55345;branch=z9hG4bK-d1d81e94a099\r\n" + + "From: ;tag=68e274dbd83b\r\n" + + "To: ;tag=gK0cacc73a\r\n" + + "Call-ID: 042736d4-0bd9-4681-ab86-7321443ff58a\r\n" + + "CSeq: 31109 INVITE\r\n" + + "Record-Route: \r\n" + + "Record-Route: \r\n" + + "Contact: \r\n" + + "Content-Type: application/sdp-lol\r\n" + + "Content-Length: 168\r\n" + + "\r\n" + + "v=0\r\n" + + "o=- 24294 7759 IN IP4 4.55.22.66\r\n" + + "s=-\r\n" + + "c=IN IP4 4.55.22.66\r\n" + + "t=0 0\r\n" + + "m=audio 19580 RTP/AVP 0 101\r\n" + + "a=rtpmap:101 telephone-event/8000\r\n" + + "a=fmtp:101 0-15\r\n" + + "a=maxptime:20\r\n" +) + type msgTest struct { name string s string @@ -796,27 +830,7 @@ var msgTests = []msgTest{ msgTest{ name: "Flowroute Fun", - s: "SIP/2.0 200 OK\r\n" + - "Via: SIP/2.0/UDP 1.2.3.4:55345;branch=z9hG4bK-d1d81e94a099\r\n" + - "From: ;tag=68e274dbd83b\r\n" + - "To: ;tag=gK0cacc73a\r\n" + - "Call-ID: 042736d4-0bd9-4681-ab86-7321443ff58a\r\n" + - "CSeq: 31109 INVITE\r\n" + - "Record-Route: \r\n" + - "Record-Route: \r\n" + - "Contact: \r\n" + - "Content-Type: application/sdp-lol\r\n" + - "Content-Length: 168\r\n" + - "\r\n" + - "v=0\r\n" + - "o=- 24294 7759 IN IP4 4.55.22.66\r\n" + - "s=-\r\n" + - "c=IN IP4 4.55.22.66\r\n" + - "t=0 0\r\n" + - "m=audio 19580 RTP/AVP 0 101\r\n" + - "a=rtpmap:101 telephone-event/8000\r\n" + - "a=fmtp:101 0-15\r\n" + - "a=maxptime:20\r\n", + s: flowroute, msg: sip.Msg{ VersionMajor: 2, Status: 200, @@ -1139,16 +1153,7 @@ var msgTests = []msgTest{ msgTest{ name: "RFC4475 Torture Message #2", - s: "!interesting-Method0123456789_*+`.%indeed'~ sip:1_unusual.URI~(to-be!sure)&isn't+it$/crazy?,/;;*:&it+has=1,weird!*pas$wo~d_too.(doesn't-it)@example.com SIP/2.0\r\n" + - "Via: SIP/2.0/TCP host1.example.com;branch=z9hG4bK-.!%66*_+`'~\r\n" + - "To: \"BEL:\\\x07 NUL:\\\x00 DEL:\\\x7F\" \r\n" + - "From: token1~` token2'+_ token3*%!.- ;fromParam''~+*_!.-%=\"\xD1\x80\xD0\xB0\xD0\xB1\xD0\xBE\xD1\x82\xD0\xB0\xD1\x8E\xD1\x89\xD0\xB8\xD0\xB9\";tag=_token~1'+`*%!-.\r\n" + - "Call-ID: intmeth.word%ZK-!.*_+'@word`~)(><:\\/\"][?}{\r\n" + - "CSeq: 139122385 !interesting-Method0123456789_*+`.%indeed'~\r\n" + - "Max-Forwards: 255\r\n" + - "extensionHeader-!.%*+_`'~:\xEF\xBB\xBF\xE5\xA4\xA7\xE5\x81\x9C\xE9\x9B\xBB\r\n" + - "Content-Length: 0\r\n" + - "\r\n", + s: torture2, msg: sip.Msg{ VersionMajor: 2, Method: "!interesting-Method0123456789_*+`.%indeed'~", @@ -1244,3 +1249,17 @@ func TestParseMsg(t *testing.T) { } } } + +func BenchmarkParseMsgFlowroute(b *testing.B) { // 27256 ns/op + msg := []byte(flowroute) + for i := 0; i < b.N; i++ { + sip.ParseMsgBytes(msg) + } +} + +func BenchmarkParseMsgTorture2(b *testing.B) { // 32296 ns/op + msg := []byte(torture2) + for i := 0; i < b.N; i++ { + sip.ParseMsgBytes(msg) + } +}