looptest

JavaScript performance comparison

Test case created

Info

Checking the performance of the loop checking

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var listObj = {
      "one": 1,
      "two": 2,
      "three": 3
    };
    var listArray = [{
      name: "one",
      value: 1
    }, {
      name: "two",
      value: 2
    }, {
      name: "three",
      value: 3
    }];
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
withObj
function getProperty(prop) {
  return listObj[prop];
}

getProperty("one");
pending…
withArray
function getProperty(prop) {
  var found = '';
  jQuery.each(listArray, function(ind, val) {
    if (val["name"] == prop) {
      found = val["value"];
      return false;
    }
  });
  return found;
}
getProperty("one");
pending…

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

Compare results of other browsers

0 comments

Add a comment