/[resiprocate]/main/resip/stack/test/testSipMessageEncode.cxx
ViewVC logotype

Contents of /main/resip/stack/test/testSipMessageEncode.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9485 - (show annotations) (download)
Sat Apr 7 00:34:03 2012 UTC (7 years, 7 months ago) by dpocock
File size: 4573 byte(s)
Switch over to autotools build system from dpocock-autotools branch
1 #if defined(HAVE_CONFIG_H)
2 #include "config.h"
3 #endif
4
5
6 #include "resip/stack/SipMessage.hxx"
7 #include <fstream>
8 #include <string>
9
10 using namespace resip;
11 using namespace std;
12
13 class Args
14 {
15 public:
16
17 Args(void):runs(100000),runFs(false),runDs(true)
18 {}
19
20 int runs;
21 bool runFs;
22 bool runDs;
23 };
24
25 void processArgs(int argc, char* argv[],Args &args);
26
27 int
28 main(int argc, char* argv[])
29 {
30 Args args;
31
32 cout << "\r\n------------------------------------------------------\r\n";
33 cout << "Resiprocate resip::SipMessage encoder speed test rev 1.0\r\n";
34 cout << "Args: [-r <number of runs>] [-runfs=(yes|no)] [-runds=(yes|no)]\r\n";
35 cout << "Example: -r 100000 -runfs=yes -runds=no\r\n";
36 cout << "------------------------------------------------------------\r\n";
37
38 processArgs(argc,argv,args);
39
40 Data txt("INVITE sip:192.168.2.92:5100;q=1 SIP/2.0\r\n"
41 "To: <sip:yiwen_AT_meet2talk.com@whistler.gloo.net>\r\n"
42 "From: Jason Fischl<sip:jason_AT_meet2talk.com@whistler.gloo.net>;tag=ba1aee2d\r\n"
43 "Via: SIP/2.0/UDP 192.168.2.220:5060;branch=z9hG4bK-c87542-da4d3e6a.0-1--c87542-;rport=5060;received=192.168.2.220;stid=579667358\r\n"
44 "Via: SIP/2.0/UDP 192.168.2.15:5100;branch=z9hG4bK-c87542-579667358-1--c87542-;rport=5100;received=192.168.2.15\r\n"
45 "Call-ID: 6c64b42fce01b007\r\n"
46 "CSeq: 2 INVITE\r\n"
47 "Record-Route: <sip:proxy@192.168.2.220:5060;lr>\r\n"
48 "Contact: <sip:192.168.2.15:5100>\r\n"
49 "Max-Forwards: 69\r\n"
50 "Content-Type: application/sdp\r\n"
51 "Content-Length: 307\r\n"
52 "\r\n"
53 "v=0\r\n"
54 "o=M2TUA 1589993278 1032390928 IN IP4 192.168.2.15\r\n"
55 "s=-\r\n"
56 "c=IN IP4 192.168.2.15\r\n"
57 "t=0 0\r\n"
58 "m=audio 9000 RTP/AVP 103 97 100 101 0 8 102\r\n"
59 "a=rtpmap:103 ISAC/16000\r\n"
60 "a=rtpmap:97 IPCMWB/16000\r\n"
61 "a=rtpmap:100 EG711U/8000\r\n"
62 "a=rtpmap:101 EG711A/8000\r\n"
63 "a=rtpmap:0 PCMU/8000\r\n"
64 "a=rtpmap:8 PCMA/8000\r\n"
65 "a=rtpmap:102 iLBC/8000\r\n");
66
67 SipMessage *msg;
68 msg = SipMessage::make(txt);
69
70 if( NULL == msg )
71 {
72 cout << "\r\nError: Unable to build test message\r\n";
73 return -1;
74 }
75
76 cout << "\r\nRunning SipMsg Encoder Speed test\r\n";
77 #ifdef RESIP_USE_STL_STREAMS
78 cout << "USING STL STREAMS\r\n";
79 #else
80 cout << "USING RESIP FAST STREAMS\r\n";
81 #endif
82
83 UInt64 startTime=0;
84 UInt64 elapsed=0;
85 double secs=0;
86
87 if( args.runFs )
88 {
89 fstream fs;
90 fs.open("_testSipMsgEncode_.txt",ios_base::out | ios_base::trunc);
91
92 if( !fs.is_open() )
93 {
94 cout << "Error opening file";
95 return -1;
96 }
97
98 cout << "\r\nOutput to file, runs = " << args.runs << ", ...\r\n";
99 startTime = Timer::getTimeMs();
100 for(int i=0; i<args.runs; i++)
101 {
102 fs << *msg;
103 }
104 elapsed = Timer::getTimeMs() - startTime;
105 secs = ((double) elapsed / 1000.0);
106
107 cout << "\r\nOutput to file completed, elapsed time= " << secs << " seconds.\r\n";
108
109 }
110
111 if( args.runDs )
112 {
113 Data data;
114 DataStream resipStr(data);
115
116 cout << "\r\nOutput to resip::DataStream, runs = " << args.runs << ", ...\r\n";
117
118 startTime = Timer::getTimeMs();
119 for(int i=0; i<args.runs; i++)
120 {
121 msg->encode(resipStr);
122 data.clear();
123 }
124 elapsed = Timer::getTimeMs() - startTime;
125 secs = ((double) elapsed / 1000.0);
126
127 cout << "\r\nOutput to resip::DataStream completed, elapsed time= " << secs << " seconds.\r\n";
128 }
129
130 cout << "Test complete.\r\n";
131
132 return 0;
133 }
134
135 void processArgs(int argc, char* argv[],Args &args)
136 {
137 if( argc <= 1 )
138 return;
139
140 for( int i=1; i<argc; i++ )
141 {
142 string arg(argv[i]);
143
144 if( arg == "-r" )
145 {
146 if( ++i >= argc )
147 {
148 cout << "\r\n Bad argument for -r, needs -r <run number>\r\n";
149 exit(-1);
150 }
151
152 int iruns = atoi(argv[i]);
153
154 if( iruns <= 0 )
155 {
156 cout << "\r\n Bad argument for -r, needs -r <run number>\r\n";
157 exit(-1);
158 }
159
160 args.runs = iruns;
161 }
162 else if( arg.substr(0,7) == "-runfs=" )
163 {
164 if( arg.substr(7) == "yes" )
165 {
166 args.runFs = true;
167 }
168 else
169 {
170 args.runFs = false;
171 }
172 }
173 else if( arg.substr(0,7) == "-runds=" )
174 {
175 if( arg.substr(7) == "yes" )
176 {
177 args.runDs = true;
178 }
179 else
180 {
181 args.runDs = false;
182 }
183 }
184 }
185 }

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27