Repository navigation
Expand file tree
/
Copy pathbenchmark.html
More file actions
181 lines (177 loc) · 13 KB
/
Copy pathbenchmark.html
File metadata and controls
181 lines (177 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>codelight.js Benchmark</title>
<meta name="description" content="codelight.js against highlight.js, Prism and Shiki on code that arrives a little at a time, and on finished files.">
<link rel="canonical" href="https://codelightjs.github.io/benchmark.html">
<meta property="og:type" content="website">
<meta property="og:site_name" content="codelight.js">
<meta property="og:title" content="codelight.js benchmark: 4.4× faster on live code">
<meta property="og:description" content="codelight.js against highlight.js, Prism and Shiki on code that arrives a little at a time, and on finished files.">
<meta property="og:url" content="https://codelightjs.github.io/benchmark.html">
<meta property="og:image" content="https://codelightjs.github.io/og.png">
<meta name="twitter:card" content="summary_large_image">
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='7' fill='%2311141a'/%3E%3Cpath d='M9 11l-4 5 4 5M23 11l4 5-4 5' stroke='%23ff7aa8' stroke-width='2.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3Ccircle cx='16' cy='16' r='3.4' fill='%23ffb86b'/%3E%3C/svg%3E">
<link rel="stylesheet" href="site.css">
<link rel="stylesheet" href="styles/default.min.css">
<style>
.big{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:1px;background:var(--border);border:1px solid var(--border);border-radius:var(--radius);overflow:hidden;margin-top:28px}
.big div{background:var(--surface);padding:16px 18px;text-align:center}
.big b{display:block;font-size:30px;line-height:1.1;color:var(--accent);font-variant-numeric:tabular-nums;letter-spacing:-.02em}
.big span{display:block;color:var(--muted);font-size:13.5px;margin-top:4px}
.table td:nth-child(2){min-width:220px}
.snippet{border:1px solid var(--border);border-radius:10px;overflow:auto;margin-top:12px}
.snippet pre{margin:0;font:13.5px/1.6 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
.snippet code.cl{padding:12px 14px}
@media (max-width:640px){.big{grid-template-columns:minmax(0,1fr)}}
</style>
</head>
<body data-page="benchmark">
<!--HEADER:START (from partials/header.html by tools/build-demo.mjs)-->
<a class="skip" href="#main">Skip to content</a>
<header class="site-header">
<div class="wrap">
<a class="brand" href="./" aria-label="codelight.js home">
<svg width="30" height="30" viewBox="0 0 32 32" aria-hidden="true"><rect width="32" height="32" rx="7" fill="#11141a"/><path d="M9 11l-4 5 4 5M23 11l4 5-4 5" stroke="#ff7aa8" stroke-width="2.6" fill="none" stroke-linecap="round" stroke-linejoin="round"/><circle cx="16" cy="16" r="3.4" fill="#ffb86b"/></svg>
<span>codelight<b>.js</b></span>
<span class="version">v1.6.1</span>
</a>
<nav class="site-nav" id="site-nav" aria-label="Main">
<a href="./#use" data-page="start">Get started</a>
<a href="./#supported-languages" data-page="languages">Languages</a>
<a href="compare.html" data-page="compare">Compare</a>
<a href="benchmark.html" data-page="benchmark">Benchmark</a>
<a href="https://github.com/codelightjs/codelight.js/tree/main/docs">Docs</a>
<a href="about.html" data-page="about">About</a>
</nav>
<div class="header-actions">
<button class="icon-btn" id="theme" type="button" aria-label="Switch theme">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 3a9 9 0 0 1 0 18z" fill="currentColor"/></svg>
</button>
<a class="btn primary gh" href="https://github.com/codelightjs/codelight.js">
<svg viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38v-1.33c-2.23.48-2.7-1.07-2.7-1.07-.36-.92-.89-1.17-.89-1.17-.73-.5.06-.49.06-.49.8.06 1.23.83 1.23.83.72 1.22 1.87.87 2.33.66.07-.52.28-.87.5-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82a7.6 7.6 0 0 1 4 0c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48v2.2c0 .21.15.46.55.38A8 8 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>
<span>GitHub</span>
</a>
<button class="icon-btn menu-btn" id="menu" type="button" aria-label="Menu" aria-expanded="false" aria-controls="site-nav">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16"/></svg>
</button>
</div>
</div>
</header>
<!--HEADER:END-->
<main id="main" class="wrap">
<div class="page-hero">
<h1>Fast on <span>live code</span>. Just as fast on finished code.</h1>
<p>A real TypeScript file arriving 4 characters at a time, about one AI token, in highlight.js, Prism, Shiki and codelight.js.</p>
<div class="big">
<div><b>4.4×</b><span>faster than highlight.js on code that's arriving</span></div>
<div><b>6 ms</b><span>per update near the end of the file, under one frame</span></div>
<div><b>28×</b><span>faster than Shiki on code that's arriving</span></div>
</div>
</div>
<section class="section">
<h2>Results</h2>
<p class="lead">The file is 282 lines (10,151 characters), so 2,538 updates. After each update, every highlighter updates the page and the browser lays it out.</p>
<div class="table-wrap">
<table class="table">
<thead><tr><th>Highlighter</th><th>Whole file, as it arrives</th><th>Per update, late in the file</th><th>Finished file, once</th><th>Size, gzipped</th></tr></thead>
<tbody>
<tr class="us"><td>codelight.js</td><td class="num"><b>7.6 s</b><div class="meter us" style="width:3.5%"></div></td><td class="num"><b>6.0 ms</b></td><td class="num"><b>21.3 ms</b></td><td class="num">16 KB, all 50+ languages</td></tr>
<tr><td>Shiki + @shikijs/stream</td><td class="num">9.0 s (1.2× slower)<div class="meter" style="width:4.1%"></div></td><td class="num">7.0 ms</td><td class="num">174 ms</td><td class="num">72.2 KB, TypeScript only</td></tr>
<tr><td>highlight.js</td><td class="num">33.9 s (4.4× slower)<div class="meter" style="width:15.6%"></div></td><td class="num">24.3 ms</td><td class="num">23.1 ms</td><td class="num">11.1 KB, TypeScript only</td></tr>
<tr><td>Prism</td><td class="num">35.3 s (4.6× slower)<div class="meter" style="width:16.2%"></div></td><td class="num">29.6 ms</td><td class="num">23.4 ms</td><td class="num">7.7 KB, TypeScript only</td></tr>
<tr><td>Shiki</td><td class="num">218 s (28.5× slower)<div class="meter" style="width:100%"></div></td><td class="num">190 ms</td><td class="num">175 ms</td><td class="num">71.6 KB, TypeScript only</td></tr>
</tbody>
</table>
</div>
<p class="note">Medians of 3 runs after a warm-up, Microsoft Edge 158 on an Intel Core i3-10110U laptop from 2020, 30 Nov 2026. "Late in the file" is the average over the last 10% of updates. Faster machines give smaller numbers; compare the ratios. Timings used codelight.js 1.3.0, highlight.js 11.12.0, Prism 1.30.0 and Shiki 4.6.0.</p>
</section>
<section class="section">
<h2>What it shows</h2>
<div class="cards two">
<div class="card"><h3>The approach is what matters</h3><p>highlight.js, Prism and Shiki redo the whole file on every update, so each update gets slower as the file grows. Near the end, their updates take 24 to 190 ms: longer than one frame at 60 fps, so the page stutters. codelight.js re-highlighting everything is just as slow. The speed comes from highlighting each finished line once.</p></div>
<div class="card"><h3>Equal on finished files</h3><p>For a page of finished code, codelight.js, highlight.js and Prism all take 21 to 23 ms for this file. Shiki takes 175 ms.</p></div>
<div class="card"><h3>Shiki's streaming package is close</h3><p><code>@shikijs/stream</code> is 1.2× codelight.js on live code, with the most exact colours. It's about four times bigger, and slow on finished files.</p></div>
<div class="card"><h3>Still room to improve</h3><p>codelight.js's cost per update still grows slowly with the file (6 ms near the end), because the browser lays out the whole block again. Giving each line its own block could keep it flat; that's on the <a href="about.html#roadmap">roadmap</a>.</p></div>
</div>
</section>
<section class="section">
<h2>How it's measured</h2>
<ul>
<li>Every highlighter runs in the same page in a real browser, doing its normal job. codelight.js calls <code>mount()</code> once and then <code>write(chunk)</code>. highlight.js, Prism and Shiki highlight the whole text so far and replace the HTML. Shiki + stream uses its <code>ShikiStreamTokenizer</code>.</li>
<li>After each update the page is laid out, as the browser would before the next frame, so drawing time counts too.</li>
<li>Every highlighter's final output was checked to contain exactly the input text.</li>
<li>Sizes are each library with only what TypeScript needs, bundled with esbuild, minified and gzipped. codelight.js can't be split by language yet, so its size includes every language.</li>
<li>Shiki used its JavaScript regex engine, which its docs recommend for browsers.</li>
</ul>
</section>
<section class="section">
<h2>Run it yourself</h2>
<p class="lead">It needs Edge or Chrome. The full run takes about 30 minutes on the laptop above; <code>BENCH_QUICK=1</code> runs a short check in about a minute.</p>
<div class="snippet"><pre><code class="language-bash">git clone https://github.com/codelightjs/codelight.js
cd codelight.js
npm install
npm run bench</code></pre></div>
<p class="note">Found something unfair in the method? Please <a href="https://github.com/codelightjs/codelight.js/issues">open an issue</a>. Full details are in <a href="https://github.com/codelightjs/codelight.js/blob/main/docs/benchmark.md">docs/benchmark.md</a>.</p>
<div class="cta-row"><a class="btn primary" href="./#try">See it stream</a><a class="btn" href="compare.html">Compare features</a></div>
</section>
</main>
<!--FOOTER:START (from partials/footer.html by tools/build-demo.mjs)-->
<footer class="site-footer">
<div class="wrap">
<div class="footer-grid">
<div class="footer-about">
<a class="brand" href="./">
<svg width="26" height="26" viewBox="0 0 32 32" aria-hidden="true"><rect width="32" height="32" rx="7" fill="#11141a"/><path d="M9 11l-4 5 4 5M23 11l4 5-4 5" stroke="#ff7aa8" stroke-width="2.6" fill="none" stroke-linecap="round" stroke-linejoin="round"/><circle cx="16" cy="16" r="3.4" fill="#ffb86b"/></svg>
<span>codelight<b>.js</b></span>
</a>
<p>Syntax highlighting that keeps up with live code. Very fast, lightweight, no dependencies.</p>
<code class="footer-install">npm i codelight.js</code>
</div>
<div>
<h2>Product</h2>
<ul>
<li><a href="./#try">Live demo</a></li>
<li><a href="./#use">Get started</a></li>
<li><a href="./#supported-languages">Languages</a></li>
<li><a href="compare.html">Compare</a></li>
<li><a href="benchmark.html">Benchmark</a></li>
</ul>
</div>
<div>
<h2>Docs</h2>
<ul>
<li><a href="https://github.com/codelightjs/codelight.js/blob/main/docs/getting-started.md">Getting started</a></li>
<li><a href="https://github.com/codelightjs/codelight.js/blob/main/docs/api.md">API</a></li>
<li><a href="https://github.com/codelightjs/codelight.js/blob/main/docs/streaming.md">Streaming</a></li>
<li><a href="https://github.com/codelightjs/codelight.js/blob/main/docs/react.md">React</a></li>
<li><a href="https://github.com/codelightjs/codelight.js/blob/main/docs/themes.md">Themes</a></li>
<li><a href="https://github.com/codelightjs/codelight.js/blob/main/docs/migrating.md">Switching from highlight.js</a></li>
</ul>
</div>
<div>
<h2>Project</h2>
<ul>
<li><a href="about.html">About</a></li>
<li><a href="https://github.com/codelightjs/codelight.js">GitHub</a></li>
<li><a href="https://www.npmjs.com/package/codelight.js">npm</a></li>
<li><a href="https://github.com/codelightjs/codelight.js/blob/main/CHANGES.md">Changelog</a></li>
<li><a href="https://github.com/codelightjs/codelight.js/issues">Report an issue</a></li>
<li><a href="https://github.com/codelightjs/codelight.js/blob/main/SECURITY.md">Security</a></li>
</ul>
</div>
</div>
<div class="footer-bottom">
<span>© 2026 <a href="https://github.com/ckgiri">CK Giri</a> · MIT licence</span>
<span>v1.6.1 · <a href="llms.txt">llms.txt</a></span>
</div>
</div>
</footer>
<!--FOOTER:END-->
<script src="site.js"></script>
<script src="codelight.min.js"></script>
<script>codelight.highlightAll(document.querySelector("main"));</script>
</body>
</html>