hexpat XML parser library
hexpat is an XML parser library available on hackage
The differentiating feature from other XML libraries is speed. So, here is a graph showing some benchmarks against two other XML libraries.
--Blackh 23:34, 26 March 2009 (UTC)
hexpat pays a penalty on the threaded runtime that other libraries don't, and this shrinks its advantage slightly.
The benchmarks are calculated in the following way:
- The graph shows results for 67 XML files ranging in size from 1 to 100 k bytes. These files were chosen at random with an even spread of sizes off my Ubuntu system.
- For each parser, we parse the XML to a tree structure, then use 'rnf' from Control.Parallel.Strategies to force evaluation of the tree.
- For each parser/file, we parse the same file repeatedly for 200 ms, then divide total CPU time by the number of iterations. This gives mean CPU time per iteration.
- The entire test suite is done 5 times, and the median of each result is taken.
There are three reasons why hexpat is faster than the other libraries:
- hexpat uses expat to do the parsing, which is a very fast parser written in C
- hexpat's tree structure contains less information than the other libraries, so hexpat is doing less work
- hexpat can optionally use the Data.Text data type, which is faster than the standard Haskell String. (Both data types are shown on the graph for hexpat.)
- Linux amentet 2.6.27-7-generic #1 SMP Tue Nov 4 19:33:06 UTC 2008 x86_64 GNU/Linux
- Intel(R) Core(TM)2 Duo CPU T7500 @ 2.20GHz
- The Glorious Glasgow Haskell Compilation System, version 18.104.22.16890314
Note: The HXT library does not work on the version of GHC I am using. The error is
benchmark: error: a C finalizer called back into Haskell. use Foreign.Concurrent.newForeignPtr for Haskell finalizers.
I will re-run the benchmark when this is fixed.
I am one of the authors of hexpat, so this makes me biased: I do not know any switches to make the other libraries work at their best speed. So that you can check yourself, here is the software that does the benchmarks, including raw results for the graphs above: