Array vs Object Setter (v8)

Revision 8 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= {"1":1, "2":2, "3":3, "4":4, "5":5, "6":6, "7":7, "8":8, "9":9, "10":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["3"] = 15;
o2["4"] = 15;
o2["6"] = 15;
o2["9"] = 15;
ready
Array access - Typed
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.