Variable, Object, Array Read speed (v2)

Revision 2 of this benchmark created on


Description

Checking the difference between variables, object properties, and array access speeds.

Setup

let x = 10;
let y = 20;

let obj = {x: 10, y:20};

let arr = [10, 20];

Test runner

Ready to run.

Testing in
TestOps/sec
Raw
let blah = x + y;

for (let i = 0; i < 100; i++) {
	blah = x + y;
}
ready
Obj
let blah = obj.x + obj.y;

for (let i = 0; i < 100; i++) {
	blah = obj.x + obj.y;
}
ready
Array
let blah = arr[0] + arr[1];

for (let i = 0; i < 100; i++) {
	blah = arr[0] + arr[1];
}
ready

Revisions

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