3 ms·
In my experiments (http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ http://blog.ianbicking.org/2008/03/30/python-html-parser-per...) lxml p
by ianb 16y ago
In my experiments (http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ http://blog.ianbicking.org/2008/03/30/python-html-parser-per...) lxml performed better than cElementTree for memory -- notably cElementTree creates Python objects for all nodes, while lxml does so only on demand (though I suppose if you ultimately touch every node in Python then lxml will use more memory).
Also lxml preserves the namespace prefixes, which while formally not necessary to understand a document are often in practice both aesthetic and sometimes necessary (e.g., RDF).
Also algorithmically, I find lxml's parent pointer on nodes to be very handy. I find some things really really hard in ElementTree because you can't directly get the parent of a node.