Script Preparation code:
x
 
function get1024Bytes(n) {
  const bytes = new Uint8Array(n * 1024);
  for (let i = 0; i < bytes.length; i += 1) {
    bytes[i] = Math.random() * 0xff;
  }
  return bytes;
}
const bytes = get1024Bytes(128);
const utf16decoder = new TextDecoder('utf-16');
// An example result:
// const binString = Array.from(bytes, (byte) => String.fromCodePoint(byte)).join("");
Tests:
  • Array.from + join + fromCodePoint

     
    return Array.from(bytes, (byte) =>
      String.fromCodePoint(byte),
    ).join("");
  • Array.from + join + fromCharCode

     
    return Array.from(bytes, (byte) =>
      String.fromCharCode(byte),
    ).join("");
  • Array.reduce + fromCodePoint

     
    return bytes.reduce((s, byte) => s + String.fromCodePoint(byte), "");
  • Array.reduce + fromCharCode

     
    return bytes.reduce((s, byte) => s + String.fromCharCode(byte), "");
  • String concatenation + fromCodePoint

     
    let s = '';
    for (const byte of bytes) {
      s += String.fromCodePoint(byte);
    }
    return s;
  • String concatenation + fromCharCode

     
    let s = '';
    for (const byte of bytes) {
      s += String.fromCharCode(byte);
    }
    return s;
  • Function.apply + Array.reduce+ fromCodePoint (chunked)

     
      const QUANTUM = 32768;
      const chunks = [];
      for (let i = 0; i < bytes.length; i += QUANTUM) {
        chunks.push(bytes.slice(i, i + QUANTUM));
      }
      return chunks.reduce((s, i) => s + String.fromCodePoint.apply(null, i), '');
  • Function.apply + Array.reduce + fromCharCode (chunked)

     
      const QUANTUM = 32768;
      const chunks = [];
      for (let i = 0; i < bytes.length; i += QUANTUM) {
        chunks.push(bytes.slice(i, i + QUANTUM));
      }
      return chunks.reduce((s, i) => s + String.fromCharCode.apply(null, i), '');
  • Function.apply + String concatenation + fromCodePoint (chunked)

     
      const QUANTUM = 32768;
      let s = '';
      for (let i = 0; i < bytes.length; i += QUANTUM) {
        s += String.fromCodePoint.apply(null, bytes.slice(i, i + QUANTUM));
      }
      return s;
  • Function.apply + String concatenation + fromCharCode (chunked)

     
      const QUANTUM = 32768;
      let s = '';
      for (let i = 0; i < bytes.length; i += QUANTUM) {
        s += String.fromCharCode.apply(null, bytes.slice(i, i + QUANTUM));
      }
      return s;
  • Function.apply + Array.reduce+ fromCodePoint (small chunks)

     
      const QUANTUM = 128;
      const chunks = [];
      for (let i = 0; i < bytes.length; i += QUANTUM) {
        chunks.push(bytes.slice(i, i + QUANTUM));
      }
      return chunks.reduce((s, i) => s + String.fromCodePoint.apply(null, i), '');
  • Function.apply + Array.reduce + fromCharCode (small chunks)

     
      const QUANTUM = 128;
      const chunks = [];
      for (let i = 0; i < bytes.length; i += QUANTUM) {
        chunks.push(bytes.slice(i, i + QUANTUM));
      }
      return chunks.reduce((s, i) => s + String.fromCharCode.apply(null, i), '');
  • Function.apply + String concatenation + fromCodePoint (small chunks)

     
      const QUANTUM = 128;
      let s = '';
      for (let i = 0; i < bytes.length; i += QUANTUM) {
        s += String.fromCodePoint.apply(null, bytes.slice(i, i + QUANTUM));
      }
      return s;
  • Function.apply + String concatenation + fromCharCode (small chunks)

     
      const QUANTUM = 128;
      let s = '';
      for (let i = 0; i < bytes.length; i += QUANTUM) {
        s += String.fromCharCode.apply(null, bytes.slice(i, i + QUANTUM));
      }
      return s;
  • utf-16 TextDecoder

     
    return utf16decoder.decode(new Uint16Array(bytes));
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Array.from + join + fromCodePoint
    Array.from + join + fromCharCode
    Array.reduce + fromCodePoint
    Array.reduce + fromCharCode
    String concatenation + fromCodePoint
    String concatenation + fromCharCode
    Function.apply + Array.reduce+ fromCodePoint (chunked)
    Function.apply + Array.reduce + fromCharCode (chunked)
    Function.apply + String concatenation + fromCodePoint (chunked)
    Function.apply + String concatenation + fromCharCode (chunked)
    Function.apply + Array.reduce+ fromCodePoint (small chunks)
    Function.apply + Array.reduce + fromCharCode (small chunks)
    Function.apply + String concatenation + fromCodePoint (small chunks)
    Function.apply + String concatenation + fromCharCode (small chunks)
    utf-16 TextDecoder

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 13 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0
Chrome 134 on Windows
View result in a separate tab
Test name Executions per second
Array.from + join + fromCodePoint 272.6 Ops/sec
Array.from + join + fromCharCode 274.9 Ops/sec
Array.reduce + fromCodePoint 1155.3 Ops/sec
Array.reduce + fromCharCode 1122.5 Ops/sec
String concatenation + fromCodePoint 1423.8 Ops/sec
String concatenation + fromCharCode 1434.4 Ops/sec
Function.apply + Array.reduce+ fromCodePoint (chunked) 532.2 Ops/sec
Function.apply + Array.reduce + fromCharCode (chunked) 1485.3 Ops/sec
Function.apply + String concatenation + fromCodePoint (chunked) 828.0 Ops/sec
Function.apply + String concatenation + fromCharCode (chunked) 1661.4 Ops/sec
Function.apply + Array.reduce+ fromCodePoint (small chunks) 786.5 Ops/sec
Function.apply + Array.reduce + fromCharCode (small chunks) 1554.6 Ops/sec
Function.apply + String concatenation + fromCodePoint (small chunks) 774.1 Ops/sec
Function.apply + String concatenation + fromCharCode (small chunks) 1601.5 Ops/sec
utf-16 TextDecoder 4179.2 Ops/sec