Skip to content

Latest commit

 

History

History
67 lines (42 loc) · 2 KB

File metadata and controls

67 lines (42 loc) · 2 KB

JS TextDecoder Benchmark

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.

Installation

Clone the repository and install dependencies:

git clone https://github.com/lemire/jstextdecoderbench.git
cd jstextdecoderbench
npm install

Browser Version

You can also run the benchmark directly in your browser: view the live demo.

Usage

Run the benchmark:

node textdecoder-benchmark.js

What it does

The benchmark:

  1. Downloads three different Unicode text samples:

  2. Encodes each text to UTF-8 bytes using TextEncoder

  3. Uses Tinybench to measure the performance of decoding each byte array back to text using TextDecoder

  4. Reports the throughput in GB/s (higher is better) and mean decoding time in milliseconds

Results

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

Dependencies

License

Public Domain. Do what you want with this code.