This project benchmarks the performance of JavaScript's TextDecoder API when decoding different types of Unicode text. Specifically, we benchmark the following function new TextDecoder('utf-8').decode(bytes). We also provide a browser benchmark.
Clone the repository and install dependencies:
git clone https://github.com/lemire/jstextdecoderbench.git
cd jstextdecoderbench
npm installYou can also run the benchmark directly in your browser: view the live demo.
Run the benchmark:
node textdecoder-benchmark.jsThe benchmark:
-
Downloads three different Unicode text samples:
-
Encodes each text to UTF-8 bytes using
TextEncoder -
Uses Tinybench to measure the performance of decoding each byte array back to text using
TextDecoder -
Reports the throughput in GB/s (higher is better) and mean decoding time in milliseconds
Node 24 with Apple M4
| Test | Size | Throughput | Mean Time |
|---|---|---|---|
| Latin lipsum (ASCII) | 84.902 KiB | 19.69 GiB/s | 0.004 ms |
| Arabic lipsum | 79.771 KiB | 0.40 GiB/s | 0.193 ms |
| Chinese lipsum | 68.203 KiB | 0.45 GiB/s | 0.144 ms |
Bun 1.3.4
| Test | Size | Throughput | Mean Time |
|---|---|---|---|
| Latin lipsum (ASCII) | 84.902 KiB | 55.83 GiB/s | 0.002 ms |
| Arabic lipsum | 79.771 KiB | 2.51 GiB/s | 0.031 ms |
| Chinese lipsum | 68.203 KiB | 5.69 GiB/s | 0.012 ms |
Public Domain. Do what you want with this code.