Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Chrome 133
Windows
Desktop
2 months ago
Test name Executions per second
array[0] 10427.7 Ops/sec
set / get 1151.4 Ops/sec
Script Preparation code:
x
 
// Setup phase - common for both tests
const size = 10000;
const array = new Array(16).fill(1); // Fill array with ones for consistency
const obj = {
    get x() {
        return array[0];
    },
    set x(value) {
        array[0] = value;
    }
};
Tests:
  • array[0]

     
    let sum = 0;
    for (let i = 0; i < size; i++) {
        array[0] = Math.random () * 1000;
        sum += array[0];
    }
  • set / get

     
    let sum = 0;
    for (let i = 0; i < size; i++) {
        obj.x = Math.random () * 1000;
        sum += obj.x;
    }