Dear Xerces Users, I found that the SAX2 API under Xerces-J is >2 times faster than the Xerces-C 's one.
I wrote two strictly equivalent programs using the lastest API : -Xerces-C 2.8 (with gcc 4.1.2) -Xerces-J 2.9.1 (with java 1.5.0) The SAX handlers do nothing (empty characters & startElement functions). The two programs parse a 16Mbytes size file (size16.xml). My programs run over a host with Linux 2.6.18-53.1.13 and 2 CPUs. The programs do ten parsing and return the mean parsing time: I get -1,6 sec with Xerces-C -0,7 sec with Xerces-J Is it normal? Is Xerces-C really slowest beacause of its internal character handling? If not, could anyone have a look of my two basic programs and give me a hint. Any particular comments? Best regards Ryad PS: The main parts of the programs are at the end of the mail I've put the C++ stuff (Makefile, sources, binary) at : http://rp.lip6.fr/~kezadri/example_xerces_c/ init & compile: //set the ROOT variable of the Makefile to the Xerces-C root (directory that contains the lib and include directory of Xerces-C) make clean make run: ./a.out "../trace/size16.xml" I've put the java stuff (jar, sources) at : http://rp.lip6.fr/~kezadri/example_xerces_java/ init & compile: CLASSPATH=$CLASSPATH:lib/xercesImpl.jar:lib/xml-apis.jar javac *.java run: java Main "../trace/size16.xml" The 16Mbytes trace file is at : http://rp.lip6.fr/~kezadri/trace ///////////////Xerces-C : main.cc//////////// void TraceHandler::characters(const XMLCh* const chars , const unsigned int length) {} void TraceHandler::startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& atts) {} ///////////////Xerces-C : TraceHandler.cc//////////// SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(); parser->setFeature(XMLUni::fgSAX2CoreValidation, validate); parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, doNamespaces); parser->setFeature(XMLUni::fgXercesSchema, doSchema); parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking); parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, namespacePrefixes); char* xmlFile = argV[1]; // the trace file to parse int meanDuration = 0; cout << "Start parsing (xerces-C)\n"; for (int i = 0; i < 10; i++) { int tstart = clock(); TraceHandler traceHandler(); parser->setContentHandler(&traceHandler); parser->setErrorHandler(&traceHandler); try { parser->parse(xmlFile); } catch (const XMLException& e) { XERCES_STD_QUALIFIER cerr << "\nAn error occurred\n Error: " << e.getMessage() << "\n" << XERCES_STD_QUALIFIER endl; XMLPlatformUtils::Terminate(); return -1; } int tend = clock(); int duration = tend - tstart; meanDuration += duration; cout << "Duration[" << i << "]: " << duration << "\n"; } meanDuration = meanDuration / 10; cout << "Mean Duration (xerces-C): " << meanDuration << "\n"; ///////////////Xerces-J : TraceHandler.java//////////// public void startElement(String namespaceURI, String localName,String qName, Attributes atts) { } public void characters(char characters[], int start, int length) {} ///////////////Xerces-J : Main.java//////////// SAXParser parser = new SAXParser(); long meanDuration = 0; System.out.println("Start parsing (xerces-J)"); for (int i = 0; i < 10; i++) { long tstart = System.currentTimeMillis(); TraceHandler h=new TraceHandler(); parser.setContentHandler(h); try { parser.parse(xmlFile); } catch (Exception e) { e.printStackTrace(); } long tend = System.currentTimeMillis(); long duration = tend - tstart; System.out.println("Duration[" + i + "]: " + duration); meanDuration += duration; } meanDuration = meanDuration / 10; System.out.println("Mean Duration (xerces-j): "+ meanDuration);
