JavaScript performance comparison

Revision 2 of this test case created

Preparation code

Benchmark.prototype.setup = function() {
    var array = [];
    var object = {};
    for (var i = 0; i < 5000; i++) {
      var key = Math.random().toString(36).substring(7);
      var value = Math.random().toString(36).substring(7);
      array.push([key, value]);
      object[key] = value;

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Iterating over array
for (i = 0; i < array.length; i++) {
  var result;
  result = array[i][0] + array[i][1];
Iterating over object's properties
for(var prop in object) {
  var result = prop + object.prop;

Compare results of other browsers


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:

1 comment

ciembor commented :

This includes inherited properties, so results will be different. There should be .hasOwnProperty condition.

Comment form temporarily disabled.

Add a comment