Thanks to visit codestin.com
Credit goes to github.com

Skip to content

lemire/jstextdecoderbench

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

TextDecoder (UTF-8) benchmark

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published