Test name | Executions per second |
---|---|
array[0] | 76786.6 Ops/sec |
set / get | 75136.3 Ops/sec |
// 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;
}
};
let sum = 0;
for (let i = 0; i < size; i++) {
array[0] = Math.random () * 1000;
sum += array[0];
}
let sum = 0;
for (let i = 0; i < size; i++) {
obj.x = Math.random () * 1000;
sum += obj.x;
}