LEPTRIS

Benchmarks · HTML

HTML, the WHATWG way

The library exposes two HTML entry points.leptris_parse_html_string implements the WHATWG tree-construction algorithm, including the adoption agency, the active formatting elements reconstruction, script-data escaped states and foster parenting, and is validated against the vendored html5lib tree-construction corpus, which currently passes 1169 of 1753 cases and improves with every release.leptris_parse_html4_string reproduces the Nokogiri and libxml2 output shape and is checked byte for byte against a 1555-case Nokogiri reference. The throughput measurements below use the WHATWG entry point in both languages.

HTML (WHATWG) — competitorC / C++RubyPython
lxml2.64×+
nokogiri1.00×+

A green cell with a single value means every measured operation in that race is ahead, and the value shown is the smallest margin. A neutral cell shows the range from the weakest to the strongest operation; hovering lists the operations that remain behind. All rows, including deficits, appear in the tables below.

C, with a Ruby reference

Parse throughput versus Nokogiri’s libxml2

The benchmark program and its Ruby reference generate byte-identical pages — one realistic page with headings, paragraphs, tables, links and entities, and one entity-laden page — and report the best of nine runs on each side. The reference measures libxml2 in process through Nokogiri.

operationleptris sidenokogiri 1.19.4standing
WHATWG parse — realistic 450 KB page13998 µs14748 µs1.05×

the conformant WHATWG tree builder at libxml2's HTML-parser throughput: full adoption-agency/script-data machinery costs nothing measurable on realistic pages

WHATWG parse — entity-laden 1.3 MB page44034 µs43953 µs1.00×

fresh runlibleptris 1.9.143-dev (main eea85cf)·best of 9·Apple M1 Max, macOS 14.1.1, arm64··bench_html_parse.c vs nokogiri_html_parse.rb — byte-identical generated pages, best-of-9 MB/s

The conformant WHATWG engine parses at the throughput of the libxml2 HTML parser on both shapes. The full tree-construction machinery carries no measurable cost on realistic pages, and the conformance gates are enforced on every release.

To reproduce: run bench_html_parse andruby nokogiri_html_parse.rb frombenchmarks/html.

Python

The leptris package versus lxml

The Python operation matrix includes one HTML parsing shape: a 200-element page with entities, parsed through each library’s HTML parser in the same process.

operationleptris sidelxml 6.0.2standing
Parse HTML (200-div page)72.05 µs190.4 µs2.64×

fresh runleptris 1.9.121.0 (binding) on libleptris 1.9.143-dev·mean per iteration·Apple M1 Max, macOS 14.1.1, arm64; Python 3.10.5··benchmarks/matrix.py — same fixtures as the Ruby matrix

HTML

Measured deficits

Every HTML operation in the result data that remains behind its competitor. There are none at present.