object vs array

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<script>
  var obj = {
   x: 1,
   y: 2
  };
 
  var arr = [1, 2];
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
object create
var o = {
 x: 1,
 y: 2
};
pending…
array create
var a = [1, 2];
pending…
obj access
obj.x = 3;
obj.y = 4;
var x = obj.x;
var y = obj.y;
pending…
array access
arr[0] = 3;
arr[1] = 4;
var x = arr[0];
var y = arr[1];
pending…
array string access
arr['0'] = 3;
arr['1'] = 4;
var x = arr['0'];
var y = arr['1'];
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment