|
reSIProcate/stack
9694
|
00001 #if defined(HAVE_CONFIG_H) 00002 #include "config.h" 00003 #endif 00004 00005 00006 #include "resip/stack/SipMessage.hxx" 00007 #include <fstream> 00008 #include <string> 00009 00010 using namespace resip; 00011 using namespace std; 00012 00013 class Args 00014 { 00015 public: 00016 00017 Args(void):runs(100000),runFs(false),runDs(true) 00018 {} 00019 00020 int runs; 00021 bool runFs; 00022 bool runDs; 00023 }; 00024 00025 void processArgs(int argc, char* argv[],Args &args); 00026 00027 int 00028 main(int argc, char* argv[]) 00029 { 00030 Args args; 00031 00032 cout << "\r\n------------------------------------------------------\r\n"; 00033 cout << "Resiprocate resip::SipMessage encoder speed test rev 1.0\r\n"; 00034 cout << "Args: [-r <number of runs>] [-runfs=(yes|no)] [-runds=(yes|no)]\r\n"; 00035 cout << "Example: -r 100000 -runfs=yes -runds=no\r\n"; 00036 cout << "------------------------------------------------------------\r\n"; 00037 00038 processArgs(argc,argv,args); 00039 00040 Data txt("INVITE sip:192.168.2.92:5100;q=1 SIP/2.0\r\n" 00041 "To: <sip:yiwen_AT_meet2talk.com@whistler.gloo.net>\r\n" 00042 "From: Jason Fischl<sip:jason_AT_meet2talk.com@whistler.gloo.net>;tag=ba1aee2d\r\n" 00043 "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" 00044 "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" 00045 "Call-ID: 6c64b42fce01b007\r\n" 00046 "CSeq: 2 INVITE\r\n" 00047 "Record-Route: <sip:proxy@192.168.2.220:5060;lr>\r\n" 00048 "Contact: <sip:192.168.2.15:5100>\r\n" 00049 "Max-Forwards: 69\r\n" 00050 "Content-Type: application/sdp\r\n" 00051 "Content-Length: 307\r\n" 00052 "\r\n" 00053 "v=0\r\n" 00054 "o=M2TUA 1589993278 1032390928 IN IP4 192.168.2.15\r\n" 00055 "s=-\r\n" 00056 "c=IN IP4 192.168.2.15\r\n" 00057 "t=0 0\r\n" 00058 "m=audio 9000 RTP/AVP 103 97 100 101 0 8 102\r\n" 00059 "a=rtpmap:103 ISAC/16000\r\n" 00060 "a=rtpmap:97 IPCMWB/16000\r\n" 00061 "a=rtpmap:100 EG711U/8000\r\n" 00062 "a=rtpmap:101 EG711A/8000\r\n" 00063 "a=rtpmap:0 PCMU/8000\r\n" 00064 "a=rtpmap:8 PCMA/8000\r\n" 00065 "a=rtpmap:102 iLBC/8000\r\n"); 00066 00067 SipMessage *msg; 00068 msg = SipMessage::make(txt); 00069 00070 if( NULL == msg ) 00071 { 00072 cout << "\r\nError: Unable to build test message\r\n"; 00073 return -1; 00074 } 00075 00076 cout << "\r\nRunning SipMsg Encoder Speed test\r\n"; 00077 #ifdef RESIP_USE_STL_STREAMS 00078 cout << "USING STL STREAMS\r\n"; 00079 #else 00080 cout << "USING RESIP FAST STREAMS\r\n"; 00081 #endif 00082 00083 UInt64 startTime=0; 00084 UInt64 elapsed=0; 00085 double secs=0; 00086 00087 if( args.runFs ) 00088 { 00089 fstream fs; 00090 fs.open("_testSipMsgEncode_.txt",ios_base::out | ios_base::trunc); 00091 00092 if( !fs.is_open() ) 00093 { 00094 cout << "Error opening file"; 00095 return -1; 00096 } 00097 00098 cout << "\r\nOutput to file, runs = " << args.runs << ", ...\r\n"; 00099 startTime = Timer::getTimeMs(); 00100 for(int i=0; i<args.runs; i++) 00101 { 00102 fs << *msg; 00103 } 00104 elapsed = Timer::getTimeMs() - startTime; 00105 secs = ((double) elapsed / 1000.0); 00106 00107 cout << "\r\nOutput to file completed, elapsed time= " << secs << " seconds.\r\n"; 00108 00109 } 00110 00111 if( args.runDs ) 00112 { 00113 Data data; 00114 DataStream resipStr(data); 00115 00116 cout << "\r\nOutput to resip::DataStream, runs = " << args.runs << ", ...\r\n"; 00117 00118 startTime = Timer::getTimeMs(); 00119 for(int i=0; i<args.runs; i++) 00120 { 00121 msg->encode(resipStr); 00122 data.clear(); 00123 } 00124 elapsed = Timer::getTimeMs() - startTime; 00125 secs = ((double) elapsed / 1000.0); 00126 00127 cout << "\r\nOutput to resip::DataStream completed, elapsed time= " << secs << " seconds.\r\n"; 00128 } 00129 00130 cout << "Test complete.\r\n"; 00131 00132 return 0; 00133 } 00134 00135 void processArgs(int argc, char* argv[],Args &args) 00136 { 00137 if( argc <= 1 ) 00138 return; 00139 00140 for( int i=1; i<argc; i++ ) 00141 { 00142 string arg(argv[i]); 00143 00144 if( arg == "-r" ) 00145 { 00146 if( ++i >= argc ) 00147 { 00148 cout << "\r\n Bad argument for -r, needs -r <run number>\r\n"; 00149 exit(-1); 00150 } 00151 00152 int iruns = atoi(argv[i]); 00153 00154 if( iruns <= 0 ) 00155 { 00156 cout << "\r\n Bad argument for -r, needs -r <run number>\r\n"; 00157 exit(-1); 00158 } 00159 00160 args.runs = iruns; 00161 } 00162 else if( arg.substr(0,7) == "-runfs=" ) 00163 { 00164 if( arg.substr(7) == "yes" ) 00165 { 00166 args.runFs = true; 00167 } 00168 else 00169 { 00170 args.runFs = false; 00171 } 00172 } 00173 else if( arg.substr(0,7) == "-runds=" ) 00174 { 00175 if( arg.substr(7) == "yes" ) 00176 { 00177 args.runDs = true; 00178 } 00179 else 00180 { 00181 args.runDs = false; 00182 } 00183 } 00184 } 00185 }
1.7.5.1