Script Preparation code:
x
 
class CustomArray extends Array {
  constructor(...args) {
    super(args);
    this.position = 0;
  }
}
class CustomUint8Array extends Uint8Array {
  constructor(...args) {
    super(args);
    this.position = 0;
  }
}
const LENGTH = 12000;
var rArray = [];
var uint8Array = new Uint8Array(LENGTH);
var uint8ArrayExp = new Uint8Array(LENGTH);
uint8ArrayExp.position = 0;
var cArray = new CustomArray(LENGTH);
var cUint8Array = new CustomUint8Array(LENGTH);
for (let i = 0; i < LENGTH; i++) {
  const v = ~~(Math.random() * 255);
  rArray.push(v);
  uint8Array[i] = v;
  uint8ArrayExp[i] = v;
  cArray[i] = v;
  cUint8Array[i] = v;
}
Tests:
  • Regular Array

     
    function read(arr, offset) {
      let pos = offset;
      while (pos < arr.length) {
        pos++;
        if (arr[pos] < 127) {
          return pos;
        }
      }
      return pos;
    }
    let o = 0;
    while (o < rArray.length) {
      o = read(rArray, o);
    }
  • Uint Array

     
    function read(arr, offset) {
      let pos = offset;
      while (pos < arr.length) {
        pos++;
        if (arr[pos] < 127) {
          return pos;
        }
      }
      return pos;
    }
    let o = 0;
    while (o < uint8Array.length) {
      o = read(uint8Array, o);
    }
  • Uint Array Expando

     
    function read(arr) {
      while (arr.position < arr.length) {
        arr.position++;
        if (arr[arr.position] < 127) {
          return arr.position;
        }
      }
      return arr.position;
    }
    let o = 0;
    uint8ArrayExp.position = 0;
    while (o < uint8ArrayExp.length) {
      o = read(uint8ArrayExp);
    }
  • Custom Array

     
    function read(arr) {
      while (arr.position < arr.length) {
        arr.position++;
        if (arr[arr.position] < 127) {
          return arr.position;
        }
      }
      return arr.position;
    }
    let o = 0;
    while (o < cArray.length) {
      o = read(cArray);
    }
  • Custom Uint Array

     
    function read(arr) {
      while (arr.position < arr.length) {
        arr.position++;
        if (arr[arr.position] < 127) {
          return arr.position++;
        }
      }
      return arr.position;
    }
    let o = 0;
    while (o < cUint8Array.length) {
      o = read(cUint8Array, o);
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Regular Array
    Uint Array
    Uint Array Expando
    Custom Array
    Custom Uint Array

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15
Safari 14 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Regular Array 938.6 Ops/sec
Uint Array 939.6 Ops/sec
Uint Array Expando 875.0 Ops/sec
Custom Array 3601176.5 Ops/sec
Custom Uint Array 3610304.0 Ops/sec