TypedArray index guarding

Benchmark created on


Description

Compare guarding techniques for "index miss" in TypedArray.

Setup

var acc = 0;
var size = 100 * 100;
var typed = new Int32Array(size);
crypto.getRandomValues(typed);

Test runner

Ready to run.

Testing in
TestOps/sec
Nullish
let idx = 0;
for (let x = 0; x < size; x++) {
  idx = typed[idx] ?? x;
  acc += idx;
}
ready
Range check
let idx = 0;
for (let x = 0; x < size; x++) {
  idx = 0 <= idx && idx < size
    ? typed[idx] : x;
  acc += idx;
}

ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.