Browse Source

Benchmarks.

pull/2/head
Justine Alexandra Roberts Tunney 11 years ago
parent
commit
2692b5df0d
1 changed files with 50 additions and 31 deletions
  1. +50
    -31
      sip/msg_test.go

+ 50
- 31
sip/msg_test.go View File

@ -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\" <sip:1_unusual.URI~(to-be!sure)&isn't+it$/crazy?,/;;*@example.com>\r\n" +
"From: token1~` token2'+_ token3*%!.- <sip:mundane@example.com>;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: <sip:+12126660420@fl.gg>;tag=68e274dbd83b\r\n" +
"To: <sip:+12125650666@fl.gg>;tag=gK0cacc73a\r\n" +
"Call-ID: 042736d4-0bd9-4681-ab86-7321443ff58a\r\n" +
"CSeq: 31109 INVITE\r\n" +
"Record-Route: <sip:216.115.69.133:5060;lr>\r\n" +
"Record-Route: <sip:216.115.69.144:5060;lr>\r\n" +
"Contact: <sip:+12125650666@4.55.22.99:5060>\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: <sip:+12126660420@fl.gg>;tag=68e274dbd83b\r\n" +
"To: <sip:+12125650666@fl.gg>;tag=gK0cacc73a\r\n" +
"Call-ID: 042736d4-0bd9-4681-ab86-7321443ff58a\r\n" +
"CSeq: 31109 INVITE\r\n" +
"Record-Route: <sip:216.115.69.133:5060;lr>\r\n" +
"Record-Route: <sip:216.115.69.144:5060;lr>\r\n" +
"Contact: <sip:+12125650666@4.55.22.99:5060>\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\" <sip:1_unusual.URI~(to-be!sure)&isn't+it$/crazy?,/;;*@example.com>\r\n" +
"From: token1~` token2'+_ token3*%!.- <sip:mundane@example.com>;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)
}
}

Loading…
Cancel
Save