Array vs Object Setter (v21)

Revision 21 of this benchmark created on


Description

JavaScript arrays are basically just objects with integer property names. Is there any performance difference when accessing an array vs an object?

Setup

a= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    a2 = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
    o= {"a":1, "b":2, "c":3, "d":4, "e":5, "f": 6, "g": 7, "h":8, "i":9, "j": 10};
    o2= {"a1":1, "a2":2, "a3":3, "a4":4, "a5":5, "a6":6, "a7":7, "a8":8, "a9":9, "a10":10};

Test runner

Ready to run.

Testing in
TestOps/sec
Array access
a[3] = 15;
a[4] = 15;
a[6] = 15;
a[9] = 15;
ready
Object access
o.d = 15;
o.e = 15;
o.g = 15;
o.i = 15;
ready
Object access 2
o["d"] = 15;
o["e"] = 15;
o["g"] = 15;
o["i"] = 15;
ready
Object access Numbers
o2["a3"] = 15;
o2["a4"] = 15;
o2["a6"] = 15;
o2["a9"] = 15;
ready
Array access - Typed
a2[3] = 15;
a2[4] = 15;
a2[6] = 15;
a2[9] = 15;
ready
Object access Numbers 2
a2[3] = 15;
a2[4] = 15;
a2[6] = 15;
a2[9] = 15;
ready

Revisions

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