Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
TextDecoder compared to String.fromCharCode
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser:
Chrome 135
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
String.fromCharCode, subarray
123794.3 Ops/sec
TextDecoder, new uint8array
5508155.0 Ops/sec
TextDecoder, subarray
5533316.0 Ops/sec
Script Preparation code:
const testLength = 1000; const startSlice = 300; const endSlice = 700; const getRandomCharCode = () => Math.floor(Math.random() * 26) + 97; // a-z letters const bytes = Array.from({length: testLength}, () => getRandomCharCode()); var buffer = new Uint8Array(bytes); var decoder = new TextDecoder(); // default 'utf-8' or 'utf8'
Tests:
String.fromCharCode, subarray
String.fromCharCode(...buffer.subarray(startSlice, endSlice));
TextDecoder, new uint8array
const slice = new Uint8Array(buffer.buffer, startSlice, endSlice - startSlice); decoder.decode(slice);
TextDecoder, subarray
decoder.decode(buffer.subarray(startSlice, endSlice))