Array vs Proxied Array

Benchmark created on


Description

Plain array access vs proxied array access.

Setup

const array = []

for (let i = 0; i < 1_000_000; i++) {
	array.push(Math.random())
}

Test runner

Ready to run.

Testing in
TestOps/sec
Summing the proxied array
const proxyArray = new Proxy({}, {
  get: (target, property) => {
    return array[property];
  }
})

let sum = 0

for (let i = 0; i < proxyArray.length; i++) {
	sum += proxyArray[i]
}

console.log(sum)
ready
Summing the plain array
let sum = 0

for (let i = 0; i < array.length; i++) {
	sum += array[i]
}

console.log(sum)
ready

Revisions

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