Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Decoding ascii: TextDecoder vs Js 2
Measure performance of ascii decoding for various string lengths.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
decodeNative
2064494.1 Ops/sec
decoderJs
1797290.5 Ops/sec
Script Preparation code:
// needed to create bytes array var encoder = new TextEncoder(); // string length, multiple of 4 - vary to get different results var n = 8; var arr = new Uint16Array(n); for (let i = 0; i < n; ++i) { arr[i] = (Math.random() * 0x10000) | 0; } var decoder = new TextDecoder(); function decodeNative(arr) { return decoder.decode(arr); } function decoderJs(buffer) { var start = 0; var end = buffer.byteLength; if (end - start < 1) { return ""; } var str = ""; for (var i = start; i < end;) { var t = buffer[i++]; if (t <= 0x7F) { str += String.fromCharCode(t); } else if (t >= 0xC0 && t < 0xE0) { str += String.fromCharCode((t & 0x1F) << 6 | buffer[i++] & 0x3F); } else if (t >= 0xE0 && t < 0xF0) { str += String.fromCharCode((t & 0xF) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F); } else if (t >= 0xF0) { var t2 = ((t & 7) << 18 | (buffer[i++] & 0x3F) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F) - 0x10000; str += String.fromCharCode(0xD800 + (t2 >> 10)); str += String.fromCharCode(0xDC00 + (t2 & 0x3FF)); } } return str; }
Tests:
decodeNative
decodeNative(arr)
decoderJs
decoderJs(arr)