#include #include #include #include #include using namespace std; using namespace xpp; #ifdef WIN32 // for long GetTickCount( void ); #include #endif /************************************************************************/ void testCount(char *fileName, char* data, int expectedCount, char* elementName) { int dataLen = strlen(data); string name = elementName; XmlPullParser xpp = XmlPullParser(); xpp.setMixedContent(true); xpp.setSupportNamespaces(false); StartTag stag = StartTag(); EndTag etag = EndTag(); int runs = (5000 - 1) / expectedCount + 1; int count = -1; // start timing cout << "TEST: " << fileName << " runs=" << runs << endl; long start = GetTickCount(); try { for(int i = 0; i < runs ; ++i) { count = 0; //xpp.setInput(buf); xpp.setInput(data, dataLen); int eventType; while((eventType = xpp.next()) != XmlPullParser::END_DOCUMENT) { if(eventType == XmlPullParser::START_TAG) { xpp.readStartTag(stag); //cout << "stag=" << stag.getQName() << endl; if(stag.getQName() == name) ++count; } } } } catch(XmlPullParserException& ex) { cerr << "Exception: " << ex.getMessage() << endl; } long end = GetTickCount(); //cout << "start=" << start << " end=" << end; double timeSecs = (double)((end - start) / 1000.0) / runs; if(expectedCount != count) cout << endl << "!!!! TEST FAILED: " << fileName <<" expected=" << expectedCount << " count=" << count << endl << endl; else cout << "TEST: " << fileName << " " << timeSecs << " [s] " << " runs=" << runs << endl; } char * loadFile(char* fileName) { FILE *stream; stream = fopen( fileName, "rb" ); if( stream == NULL ) { cerr << "File " << fileName << " could not be opened " << endl; exit(1); } fseek( stream, 0L, SEEK_END); int size = ftell( stream ); cout << fileName << " size=" << size << endl; fseek( stream, 0L, SEEK_SET); char * buf = (char *) malloc(size * sizeof(*buf) + 1); int read = fread( buf, sizeof(*buf), size, stream); cout << fileName << " read=" << read << endl; buf[read] = 0; fclose( stream ); return buf; /* MUCH MUCH TOO SLOW for 2M file ifstream inputFile(inputName, ios::in); if (!inputFile) { } //string inputXML; string buffer; //int const lineSize=1000; while (!inputFile.eof() ) { //buffer += inputXML; //cout << "next string is: " << inputXML << endl; string line; getline(inputFile, line); buffer += line ; buffer += "\n"; } return buffer; */ } void testFile(char *fileName, int expectedCount, char *elementName) { //string content = loadFile(fileName); //char *buf = (char *)(content.c_str()); char * buf = loadFile(fileName); //cerr << "input=" << buf << endl; testCount(fileName, buf, expectedCount, elementName); } void main(int argc, char **argv) { cout.setf(ios::fixed, ios::floatfield); cout.precision(4); testFile("c:\\java\\exxp\\samples\\list_soapized_1.xml", 1, "iint"); testFile("c:\\java\\exxp\\samples\\list_soapized_100.xml", 100, "iint"); //testFile("c:\\java\\exxp\\samples\\list_soapized_10000.xml", 10000, "iint"); }