This is an English version of my article on Habr (in Russian).

A week ago I wrote about z3l.FastHtmlParser, an HTML parser for .NET that builds a flat list of tags instead of a DOM and parses a page 10–30x faster than HtmlAgilityPack and AngleSharp. Back then it had no CSS selectors, no XPath, and lived only in .NET.

In one week it got CSS selectors and XPath 1.0, and the library itself moved to seven more languages: Go, Rust, Java, TypeScript, Python, PHP and Ruby. These are not "Hello world" ports: each implementation is 6–11 thousand lines — a tokenizer, the HTML5 optional end tag rules, all 2,125 named entities, XPath 1.0 and CSS selectors. The algorithm is the same everywhere, and every port is checked against the original on the same pages.

The result is an experiment you rarely get to run: the same real-world task, eight languages, two operating systems and one CPU. So I can finally answer the question people get flamed for in the comments. Grab your pitchforks.

Setup

  • Same hardware. A physical server with an AMD Ryzen 7 3800X (8 cores, 16 threads).
  • Linux — Ubuntu 26.04 on that server, benchmarks in Docker, official images: dotnet/sdk:10.0, golang:1.27, rust:1.100, maven:3-eclipse-temurin-21, node:26, python:3.14, php:8.4-cli, ruby:4.0.
  • Windows — Windows 10 LTSC in a KVM virtual machine on the same server, 12 vCPUs. Same versions: .NET 10.0.12, Go 1.27.4, Rust 1.100, Java 21.0.13, Node 26.13, Python 3.14.10, PHP 8.4.27, Ruby 4.0.9.
  • PHP runs with opcache and the tracing JIT on both OSes. Ruby runs without JIT, and on Linux also with YJIT and the new ZJIT (the RubyInstaller build for Windows has no YJIT).
  • Strictly one at a time. No benchmark ran alongside another, and Linux and Windows never ran at the same time either. It's a production server running MySQL, RabbitMQ and a dozen services, so background load isn't zero (load average 1–3 out of 16), but it's the same for both OSes.
  • Two tasks. Parsing a page, and scraping — parsing plus extracting 20 books (title, price, rating) or 10 quotes. The pages are saved copies of books.toscrape.com (51 KB), quotes.toscrape.com (11 KB), webscraper.io laptops (38 KB), books ×10 (510 KB), and books with no </li> and </p>. Before measuring, every benchmark checks that all libraries returned the same records.
  • Time is the median per call after warm-up. C# uses BenchmarkDotNet, Go uses testing.B (median of three runs), the rest use the same loop: one second of warm-up, then batches of calls, take the median.
  • Error margin is up to 10%. Repeated runs of the same benchmark differed by up to 10%: C# on books — 55 and 58 μs on Linux, 64 and 59 μs on Windows; Java on Windows — 73 μs yesterday and 66 μs today. So in this article, any difference under 10% is a tie.

Results

Parsing books.toscrape.com, 51 KB (lower is better):

Place Language Linux Windows
1–4 Python (Rust inside) 54 μs 67 μs
1–4 C# 55 μs 64 μs
1–4 Rust 56 μs 61 μs
1–4 Java 59 μs 66 μs
5 Go 84 μs 102 μs
6 Node.js (TypeScript) 183 μs 201 μs
7 PHP + JIT 360 μs 516 μs
8 Ruby + YJIT 818 μs —
9 Ruby 1.60 ms 1.53 ms

The top four are within the error margin.

Parsing, all pages — Linux and Windows

Linux:

Page Rust C# Python Java Go Node.js PHP Ruby Ruby + YJIT
quotes, 11 KB 15 μs 16 μs 17 μs 17 μs 24 μs 65 μs 110 μs 466 μs 240 μs
laptops, 38 KB 46 μs 51 μs 47 μs 62 μs 74 μs 173 μs 303 μs 1.40 ms 1.22 ms
books, 51 KB 56 μs 55 μs 54 μs 59 μs 84 μs 183 μs 360 μs 1.60 ms 818 μs
books ×10, 510 KB 563 μs 611 μs 546 μs 617 μs 857 μs 2.27 ms 3.59 ms 15.3 ms 8.02 ms
books without </li> </p> 52 μs 61 μs 55 μs 63 μs 82 μs 234 μs 390 μs 1.83 ms 1.49 ms

Windows:

Page Rust C# Python Java Go Node.js PHP Ruby
quotes, 11 KB 17 μs 20 μs 18 μs 19 μs 29 μs 68 μs 153 μs 455 μs
laptops, 38 KB 50 μs 54 μs 56 μs 66 μs 88 μs 204 μs 448 μs 1.31 ms
books, 51 KB 61 μs 64 μs 67 μs 66 μs 102 μs 201 μs 516 μs 1.53 ms
books ×10, 510 KB 602 μs 637 μs 654 μs 677 μs 944 μs 2.27 ms 5.11 ms 15.4 ms
books without </li> </p> 55 μs 61 μs 63 μs 71 μs 100 μs 224 μs 514 μs 1.91 ms

Scraping 20 books (parse + extract), Linux / Windows. Every port has three ways to search: its own Find methods, CSS selectors and XPath.

Language Find API CSS XPath
Rust 73 / 82 μs 73 / 87 μs 117 / 191 μs
C# 75 / 70 μs 74 / 82 μs 117 / 109 μs
Java 86 / 93 μs 120 / 111 μs 102 / 108 μs
Go 106 / 129 μs 117 / 131 μs 216 / 265 μs
Python 117 / 155 μs 94 / 128 μs 123 / 243 μs
Node.js 230 / 239 μs 285 / 275 μs 269 / 304 μs
PHP 514 / 636 μs 609 / 758 μs 784 / 927 μs
Ruby + YJIT 1.01 ms / — 1.15 ms / — 1.30 ms / —
Ruby 2.08 / 2.14 ms 2.21 / 2.22 ms 3.05 / 2.75 ms

The ports vs. the local champions

Comparing languages is fun, but a user cares about something else: is the port worth taking over what their ecosystem already uses? The ports were written in a week and are clearly less polished than the original. Here's how they stack up against the best each platform had before them.

Parsing books.toscrape.com, 51 KB — how many times faster the port is (Linux / Windows; below 1 means the port is slower):

Language Port, Linux Fastest competitor Port is faster Popular choice Port is faster
Rust 56 μs tl 1.5x / 1.7x scraper (html5ever) 22x / 25x
C# 55 μs HtmlAgilityPack 12x / 12x AngleSharp 21x / 18x
Python 54 μs selectolax (lexbor, C) 8.4x / 6.3x BeautifulSoup 226x / 213x
Java 59 μs Jericho 6.7x / 6.0x jsoup 8.0x / 7.2x
Go 84 μs golang.org/x/net/html 10x / 9.6x goquery 10x / 9.6x
Node.js 183 μs htmlparser2 5.3x / 4.3x cheerio 16x / 9.9x
PHP 360 μs Dom\HTMLDocument (lexbor, C) 1.5x / 1.5x DOMDocument (libxml2, C) 2.6x / 2.8x
Ruby + YJIT 818 μs Nokogiri (libxml2, C) 1.3x / — Nokogiri 1.3x / —
Ruby 1.60 ms Nokogiri (libxml2, C) 0.6x / 0.9x Nokogiri 0.6x / 0.9x

Scraping 20 books — the best of the port's three APIs vs. the best competitor:

Language Port, Linux Fastest competitor Port is faster
Rust 73 μs tl (CSS) 1.7x / 2.1x
C# 74 μs HtmlAgilityPack (XPath) 11x / 12x
Python 94 μs selectolax (CSS) 6.2x / 4.8x
Java 86 μs jsoup (CSS) 8.2x / 7.5x
Go 106 μs goquery (CSS) 9.1x / 8.3x
Node.js 230 μs node-html-parser 6.1x / 4.9x
PHP 514 μs Dom\HTMLDocument (CSS) 1.4x / 1.6x
Ruby + YJIT 1.01 ms Nokogiri (XPath) 1.9x / —
Ruby 2.08 ms Nokogiri (XPath) 0.9x / 1.1x

In seven languages out of eight, the port is faster than anything the ecosystem had — on both OSes and in both tasks. And in Python, PHP and Ruby the main competitors are written in C: selectolax and Dom\HTMLDocument are lexbor; lxml, DOMDocument and Nokogiri are libxml2. Pure PHP beats the C parser built into PHP 8.4 by 1.5x.

The closest competitor is tl in Rust, only 1.5–2x slower. But tl is a zero-copy parser that doesn't decode entities and has no descendant combinator in its selectors, so it does less work.

Ruby is a special case. Without JIT, the port is on par with Nokogiri on Windows (parsing 8% slower, scraping 14% faster) and loses on Linux, where Nokogiri is noticeably faster: 1.6x on parsing. With YJIT the port overtakes Nokogiri: 1.3x on parsing and 1.9x on scraping.

Where does the gap come from? The C libraries do ten times more work: they build a full DOM tree with an object per node, synthesize implicit <html> and <tbody>, and then wrap the found nodes in Python, PHP or Ruby objects. A parser that stores tags as pairs of integer offsets into the source string does exactly what scraping needs, and nothing more.

And now — why every row of these tables will offend somebody.

Claim 1. Python caught up with Rust

On Linux, Python parses the page in 54 μs and Rust in 56. On Windows, 67 and 61.

Of course, this is cheating: the Python version is 790 lines of PyO3 bindings around the Rust version. Inside fh.parse(html) it's not the interpreter running, it's the same machine code as in Rust. And Python being 2 μs faster than Rust itself on Linux is noise and build flags: the Python wrapper is built with fat LTO, the Rust benchmark with thin LTO.

Scraping shows what Python pays for: crossing the boundary. Every found tag and every string becomes a Python object, and the Find API falls 1.6x behind pure Rust (117 μs vs. 73). CSS selectors are only 30% behind (94 μs): the whole search runs inside Rust and the boundary is crossed once. The less often your code jumps between Python and Rust, the closer it gets to Rust.

The provocation is elsewhere, though. In the "Python is slow" debate people tend to forget that in production, Python doesn't run the hot code anyway: numpy, pandas, lxml, selectolax, pydantic-core and orjson are written in C or Rust. Python is the language you call fast code from. And if your task has a native core, a Python service will beat an "honest" Go service that does everything itself.

The moral: a "fast language" is often a language that delegates well.

Claim 2. Go is the slowest of the compiled languages

Go parses the page in 84 μs — 1.5x slower than Rust, C#, Java and even Python. Same on Windows: 102 μs vs. 61–67.

And the Go version is written carefully: 2 allocations per parse, the garbage collector barely shows up in the measurement. It's not the GC, it's the compiler. The Go compiler deliberately optimizes less in exchange for build speed: more modest inlining, fewer bounds checks eliminated, no auto-vectorization. Go does have PGO, but only from a pre-recorded profile (default.pgo), and few people enable it. The JIT in .NET and HotSpot collects the profile itself, at run time, and compiles for the hot paths.

Go is still a great language for services — fast builds, simplicity, predictability. But "Go is fast because it's compiled" is a myth. It's fast compared to Python and Ruby. Not compared to the JVM and .NET.

Claim 3. C# and Java are almost Rust. And "C# beat Rust" is a Windows thing

On Linux, parsing: C# — 55 μs, Rust — 56, Java — 59. Scraping: Rust — 73, C# — 75, Java — 86. A tie, with Java slightly behind.

Windows tells a different story: on scraping, C# is first at 70 μs vs. 82 for Rust, and on XPath the gap is almost 2x: 109 μs vs. 191. The first draft of this article was titled "C# beat Rust". Then I looked at Linux, where Rust and C# are neck and neck, and started digging.

The cause is the allocator. .NET allocates objects on its own heap the same way on every OS: by bumping a pointer. Rust uses the system allocator by default: glibc malloc on Linux, HeapAlloc on Windows. The XPath engine creates lots of small vectors and strings, and the Windows system heap struggles with that. Two lines, and Rust on Windows switches to mimalloc:

#[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; 
Rust on Windows HeapAlloc (default) mimalloc For reference: Linux
Parse books, 51 KB 61 μs 55 μs 56 μs
Scrape, Find API 82 μs 69 μs 73 μs
Scrape, XPath 191 μs 125 μs 117 μs

And C# is no longer ahead: 70 μs vs. 69. On Linux mimalloc changes nothing (parsing 55 vs. 56 μs, XPath 117 vs. 117): glibc malloc is already good for this workload.

The moral: a garbage-collected language brings its own allocator, the same everywhere, while Rust gets whatever the OS gives it. On Windows that costs Rust up to 1.5x.

One more note on fairness: the C# version is the original and the most polished: ArrayPool, Span<char>, vectorized IndexOfAny, CollectionsMarshal.SetCount, Dictionary.AlternateLookup to look up by span without allocating strings. But the Java version, which has none of that, is only 5–18% behind Rust. If you want "almost Rust" without the borrow checker, these are your languages.

Claim 4. NativeAOT is slower than JIT, and server GC doesn't help

Since C# is in the top four, let's see how to make it faster. Two popular ideas: compile ahead of time (NativeAOT) and turn on the server garbage collector. BenchmarkDotNet built NativeAOT for the same instruction set the JIT uses on this CPU (x86-64-v3, AVX2), so that's not the issue.

C#, time; in parentheses — relative to regular JIT on the same OS:

Task OS JIT JIT + server GC NativeAOT NativeAOT + server GC
Parse books, 51 KB Linux 58 μs 66 μs (1.14) 75 μs (1.30) 81 μs (1.40)
Windows 59 μs 64 μs (1.08) 83 μs (1.40) 87 μs (1.47)
Parse books ×10, 510 KB Linux 614 μs 625 μs (1.02) 765 μs (1.24) 823 μs (1.34)
Windows 600 μs 626 μs (1.04) 824 μs (1.37) 864 μs (1.44)
Scrape 20 books, Find API Linux 72 μs 80 μs (1.11) 89 μs (1.24) 100 μs (1.40)
Windows 73 μs 75 μs (1.02) 100 μs (1.36) 104 μs (1.41)
Scrape 20 books, XPath Linux 121 μs 150 μs (1.24) 153 μs (1.26) 181 μs (1.50)
Windows 129 μs 132 μs (1.02) 156 μs (1.21) 169 μs (1.31)
Scrape 10 quotes Linux 25 μs 27 μs (1.06) 32 μs (1.27) 35 μs (1.41)
Windows 25 μs 26 μs (1.05) 37 μs (1.45) 38 μs (1.50)

NativeAOT is 20–50% slower than JIT. The main reason is dynamic PGO. The .NET JIT first compiles a method quickly and with instrumentation, watches which branches are hot and which types actually show up at interface calls, and then recompiles for that: devirtualizes calls, inlines the hot code, lays out code so the hot path runs straight through. NativeAOT compiles everything ahead of time, blind. Static PGO for NativeAOT exists, but almost nobody uses it.

Server GC is 2–15% slower, and up to 24% on XPath, where allocations are heaviest. Server GC has a heap per core and a much larger gen0 budget: fewer collections, but new objects land in memory that's no longer in cache. In a single-threaded parser that's a pure loss; server GC pays off when many threads allocate at once.

NativeAOT is about millisecond startup, compact deployment and no JIT at run time. Not about peak speed.

Claim 5. Node.js is 3.3x slower than Rust — and that's a great result

V8 is a marvel of engineering. A dynamically typed language with a JIT stays within 3.3x of Rust on parsing (183 μs vs. 56) and 3.1x on scraping. No other dynamic language in this table comes close: PHP is 2x slower than Node.js, Ruby with YJIT 4.5x.

The main bottleneck isn't even V8, it's JavaScript strings: UTF-16, immutable, no cheap slice views. A parser built on offsets into the source string fits that model well — which is why the gap is so small.

Claim 6. Ruby: YJIT doubles the speed

Ruby 4.0 on Linux — the port vs. Nokogiri:

Task Port, no JIT Port, ZJIT Port, YJIT Nokogiri (libxml2)
Parse books, 51 KB 1.60 ms 1.25 ms 818 μs 1.01 ms
Parse books ×10, 510 KB 15.3 ms 12.1 ms 8.02 ms 9.58 ms
Parse books without </li> </p> 1.83 ms 1.64 ms 1.49 ms 1.01 ms
Scrape 20 books 2.08 ms 1.42 ms 1.01 ms 1.90 ms
Scrape 10 quotes 789 μs 529 μs 375 μs 964 μs

YJIT makes pure Ruby twice as fast on both parsing and scraping. The new ZJIT in Ruby 4.0 gives less for now: +28% on parsing and +46% on scraping. Nokogiri doesn't speed up with JIT at all — its hot code is in C — so with YJIT the pure-Ruby port beats it almost everywhere.

The exception is the page without end tags: the Ruby version spends 14–25% more time on it than on the normal page, and 80% more with YJIT, while Rust, Go and Python don't notice the difference. Something to optimize.

A shame about Windows: RubyInstaller builds have no YJIT, so there Ruby stays an interpreter.

Claim 7. Windows vs. Linux: it's not the VM

Windows runs in a VM on the same server as Linux, so the first suspect is virtualization. Rust with mimalloc clears it: 55 μs in the Windows VM and 55 μs on bare-metal Linux. For this workload virtualization costs almost nothing.

How much slower Windows is than Linux on the same hardware (parsing books, 51 KB):

What Linux Windows Windows slower by
Rust, system allocator 56 μs 61 μs 9%
Rust + mimalloc 55 μs 55 μs 0%
C# (two runs) 55–58 μs 59–64 μs 2–17%
Java 59 μs 66 μs 12%
Node.js 183 μs 201 μs 10%
Go 84 μs 102 μs 22%
Python (Rust inside) 54 μs 67 μs 24%
PHP + JIT 360 μs 516 μs 43%
Ruby 1.60 ms 1.53 ms −4%
lxml (Python, libxml2) 590 μs 1.51 ms 156%
Dom\HTMLDocument (PHP, lexbor) 524 μs 777 μs 48%
Nokogiri (Ruby, libxml2) 1.01 ms 1.41 ms 40%
selectolax (Python, lexbor) 455 μs 421 μs −7%
htmlparser2 (Node.js) 977 μs 870 μs −11%

What follows from this:

  • Runtimes with their own allocator — .NET, the JVM, V8 — perform the same on both OSes, within noise. That holds for third-party libraries on them too: jsoup and AngleSharp differ by 1–3%.
  • Rust and the Python wrapper over Rust slow down on Windows because of the system heap (see claim 3). On XPath in Python the gap is almost 2x: 243 μs vs. 123.
  • Interpreters and C libraries depend on the build. One reason for PHP: the official Windows builds are made with MSVC, which doesn't support computed goto, so the Zend VM runs in the slower CALL mode instead of HYBRID. lxml is 2.6x slower on Windows, Nokogiri 40%. But it goes the other way too: selectolax and htmlparser2 are 7–11% faster on Windows. It all comes down to the specific build of the specific library.
  • Go is 22% slower on Windows, even though it has its own allocator. I have no explanation — hints in the comments are welcome.

A separate provocation: if your PHP service, or your Python service with lxml, runs on Windows, moving to Linux will give you more than rewriting it in another language.

Claim 8. The fastest language isn't the most verbose

Non-blank lines for the same functionality:

Language Lines
TypeScript 5,950
C# 6,950
Java 7,170
Go 8,800
Ruby 8,900
PHP 10,100
Rust 10,750
Python 790 (bindings over Rust)

The Rust version is one of the fastest and the longest. Ruby, famous for being concise, came out longer than C# and Java: when you write a parser in Ruby that has to be fast, idiomatic Ruby ends and manual index juggling in strings begins. TypeScript came out shortest.

Caveats, without which I'd rightly get torn apart

  • One algorithm, one author, one task. HTML parsing is string work and branching; for number crunching, multithreading or I/O the picture may be different.
  • The ports aren't equally optimized. The C# version is the original, the rest are week-old ports. Go and Ruby surely have room to speed up. Pull requests that move your language up the table are welcome.
  • Different benchmark harnesses and up to 10% noise. BenchmarkDotNet, testing.B and a hand-written median loop measure slightly differently, and the server isn't idle. A 10% gap between neighboring rows is a tie; a 2x gap is not.
  • Everything is default. Go without PGO, Rust without target-cpu=native and with the system allocator, as in most projects. Vectorized character search in Rust (memchr) detects AVX2 at run time on its own.
  • Python is Rust. I said it. A pure Python implementation would land around Ruby, or even below.
  • Windows is in a VM. It costs our parsers nothing (Rust + mimalloc), but for libraries that build large DOM trees virtualization may cost more: TLB misses under two-level address translation are more expensive.
  • Single-threaded measurement. In multithreaded scraping, GCs, allocators and threading models come into play — and server GC may look different. That's a topic for a separate article.

Bottom line

If the flame war really needs a one-liner: for parsing, Rust ≈ C# ≈ Java ≈ Python (Rust inside) > Go > Node.js > PHP > Ruby + YJIT > Ruby.

But if you want your scraper to be faster, switching languages isn't the first thing to do:

  • The language, with the same algorithm, gives 1.5x between the top four and Go, 3.3x to Node.js, 6.4x to PHP.
  • The algorithm, within one language, gives 1.5x to 226x over local libraries, and the PHP and Ruby ports beat C libraries.
  • Runtime settings weigh almost as much as the language: NativeAOT instead of JIT is 20–50% slower, the Windows system allocator makes Rust up to 1.5x slower, Windows instead of Linux makes PHP 43% slower.

Data structures matter more than the language, and the runtime and OS matter almost as much as the language.

All eight implementations and the benchmarks are open — run them on your hardware and send me your numbers. For C#, the JIT/NativeAOT and workstation/server GC variants run with one command: dotnet run -c Release --project benchmarks/z3l.FastHtmlParser.Benchmarks -- --runtime-variants --filter '*ParseBenchmarks.FastHtmlParser' '*ScrapeBenchmarks.*_FastHtmlParser*'.

Disclosure: the ports were written with heavy help from Claude (that's what the meme is about), and this English text is an AI-assisted translation of my original Russian article. The benchmarks and numbers are mine, run on my hardware.