overview #
syntax-highlighter-bench is a benchmark suite and results site for JS syntax highlighters. It compares Twinkleplop, Prism, Shiki, and fuz_code, with Shiki's JS engine and its Oniguruma wasm engine counted as two libraries.
A run produces one results file holding many metrics, and the site is a view over that file where a reader picks the libraries, languages, and metrics to compare: the results page.
AI disclosure: this is an LLM-generated repo guided by a person.
What is measured #
Every library is run on the same inputs, each labeled by its source. Real code that no measured library authored is the primary set and the only one the headline figures use; a library's own samples and the inputs built to find worst cases are summarized apart from it — see corpus. A language is timed only when every library supports it — see languages and sets.
The numbers are of two classes, kept apart in the results file.
Machine-dependent, published from one named machine, with each library alone in a process of its own — see method:
- Throughput: how long a warm library takes on each input, in two modes,
tokenize(tokens out) andhtml(the HTML string a consumer ships). The peak memory of its process is recorded beside it, which on a small input follows what the measuring allocated more than what the library holds. - Cold start: how long a fresh Node process takes to import a library alone, with one language, and with a documentation site's languages, and to produce a first highlight. Each is measured for the bundled chunk and for the library imported unbundled, beside a bare Node baseline to subtract, with the process's peak memory.
Deterministic, the same on any machine, committed as results/deterministic.json — see deterministic metrics:
- Bundle size for each feature set: minified, gzip, and brotli, with the wasm binary and the theme CSS reported apart from the JS.
- Token counts: each library's own, recorded and never equalised, since libraries split the same source differently.
- Output sizes: the HTML of each input, raw and compressed.
- Retained heap: what a library holds after loading one language and highlighting once, as V8's heap, its machine code, and external memory. Unlike the others it is the same only for a Node version and architecture, and within a small tolerance.
- Install footprint: the packages, files, and bytes that installing a library adds.
- Coverage: which library claims which language.
A language a library doesn't claim is unsupported, and a claimed one whose output fails the check before measuring is excluded. The two are recorded differently, and neither is ever a zero or part of a mean.
What is not measured: the quality of the highlighting, anything in a browser, a library's async path, and what one library offers that another doesn't. The numbers compare the work the libraries share, in Node, through each one's synchronous calls. The caveats say what else to hold against them.
What exists #
Three parts are built: the harness that times the libraries, warm and from a cold start, the
deterministic measurements, and the pages that render a results file. The harness is bench/, which runs on Node directly and is never imported by the site, and the
site is src/routes/ and src/lib/, built as static pages.
- an adapter for each library, in
bench/libraries/, and the output check each passes before it is measured, inbench/check_output.ts— see adapters - the inputs and their manifest, in
bench/corpus/— see corpus - the language ids and the feature sets, in
bench/langs.tsandbench/sets.ts— see languages and sets - the timed harness, which measures each library alone in a process of its own and writes a
results file, in
bench/run.tsandbench/cell.ts— see method - cold start, part of the same run, where each sample is a fresh process that imports a
library and stops its own clock, in
bench/coldstart.ts— see method - the deterministic measurements, listed below, in
bench/deterministic.ts, with their numbers committed asresults/deterministic.json— see deterministic metrics - the runs the harness writes, in
results/, where a published timed run goes beside the deterministic file asresults/latest.json— see results file - the schema of the results file, which the harness and the site share, in results_schema.ts, with bench_constants.ts, the id lists it builds its enums from — see results file
- the landing page and the results page, which render one validated results file, in
src/routes/andsrc/lib/— see results file for which file
Neutrality #
The maintainer of this benchmark also maintains fuz_code, one of the measured libraries, so fairness has to come from the structure rather than from trust:
- the maintainer's library is flagged in the results file and on the site
- every input is labeled by its source, and real code that no measured library authored is the primary set; a snippet or a stress input written for this benchmark is labeled as that, never as neutral, and no stress input is tuned to a library
- each library is driven through one adapter with notes on the entry points it uses, so its maintainers can review or replace it
- the method and the commands to reproduce a run are published with the numbers