Below are benchmarks of a variety of XML parsers with real world data.

All parsers were used to build a tree, either using XML::Simple or directly in the case of XML::LibXML. No testing was performed on the speed of extracting data from the tree.

Testing aircan (Airfare search results)

info: Parsing with XML::LibXML 1.69 appears successful
info: Parsing with XML::Parser 2.34 (via XML::Simple 2.18) appears successful
info: Parsing with XML::LibXML::SAX 1.69 (via XML::Simple 2.18) appears successful
info: Parsing with XML::LibXML::SAX::Parser 1.69 (via XML::Simple 2.18) appears successful
info: Parsing with XML::SAX::ExpatXS 1.31 (via XML::Simple 2.18) appears successful
info: Parsing with XML::SAX::PurePerl 0.96 (via XML::Simple 2.18) appears successful

                            Rate XML::SAX::PurePerl XML::LibXML::SAX XML::LibXML::SAX::Parser XML::SAX::ExpatXS XML::Parser XML::LibXML
XML::SAX::PurePerl       0.440/s*                --             -51%                     -76%              -88%        -91%        -99%
XML::LibXML::SAX         0.898/s               104%               --                     -50%              -75%        -82%        -98%
XML::LibXML::SAX::Parser  1.80/s               309%             101%                       --              -50%        -64%        -96%
XML::SAX::ExpatXS         3.57/s               712%             298%                      98%                --        -29%        -93%
XML::Parser               5.04/s              1045%             461%                     180%               41%          --        -90%
XML::LibXML               50.8/s             11440%            5555%                    2720%             1321%        907%          --


Testing sysrates (Airfare search results)

info: Parsing with XML::LibXML 1.69 appears successful
info: Parsing with XML::Parser 2.34 (via XML::Simple 2.18) appears successful
info: Parsing with XML::LibXML::SAX 1.69 (via XML::Simple 2.18) appears successful
info: Parsing with XML::LibXML::SAX::Parser 1.69 (via XML::Simple 2.18) appears successful
info: Parsing with XML::SAX::ExpatXS 1.31 (via XML::Simple 2.18) appears successful
info: Parsing with XML::SAX::PurePerl 0.96 (via XML::Simple 2.18) appears successful

                           s/iter XML::LibXML::SAX XML::SAX::PurePerl XML::LibXML::SAX::Parser XML::SAX::ExpatXS XML::Parser XML::LibXML
XML::LibXML::SAX             2.67*              --                -7%                     -61%              -79%        -84%        -99%
XML::SAX::PurePerl           2.47*              8%                 --                     -58%              -77%        -83%        -99%
XML::LibXML::SAX::Parser     1.04             156%               137%                       --              -46%        -60%        -98%
XML::SAX::ExpatXS           0.563             374%               338%                      85%                --        -26%        -96%
XML::Parser                 0.417             541%               493%                     151%               35%          --        -95%
XML::LibXML                0.0223           11874%             10977%                    4582%             2426%       1769%          --


Testing jacob (Some small UTF-16le file)

info: Parsing with XML::LibXML 1.69 appears successful
info: Parsing with XML::Parser 2.34 (via XML::Simple 2.18) appears successful
info: Parsing with XML::LibXML::SAX 1.69 (via XML::Simple 2.18) appears successful
info: Parsing with XML::LibXML::SAX::Parser 1.69 (via XML::Simple 2.18) appears successful
info: Parsing with XML::SAX::ExpatXS 1.31 (via XML::Simple 2.18) appears successful
error: Unable to parse with XML::SAX::PurePerl 0.96 (via XML::Simple 2.18)! UTF-16:Unrecognised BOM 3f3e**

                           Rate XML::LibXML::SAX::Parser XML::LibXML::SAX XML::SAX::ExpatXS XML::Parser XML::LibXML
XML::LibXML::SAX::Parser  108/s                       --             -30%              -47%        -61%        -96%
XML::LibXML::SAX          153/s                      42%               --              -25%        -44%        -95%
XML::SAX::ExpatXS         206/s                      90%              34%                --        -25%        -93%
XML::Parser               275/s                     155%              79%               34%          --        -91%
XML::LibXML              3080/s                    2750%            1908%             1396%       1019%          --

* — Too few iterations for a reliable count. Suffice it to say they were slooooow.

** — Not only is XML::SAX::PurePerl very slow, it has some encoding-related bugs. Do yourself a favour and remove it from your $perl5lib/XML/SAX/ParserDetails.ini file!!

Benchmark code

Links to modules:

Update: Added XML::SAX::ExpatXS.


In reply to Benchmarks of XML Parsers by ikegami

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.