loop-test-123

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var arr1, funcA, funcB, execute;
    arr1 = [];
   
    for (x = 0; x < 50; x += 1) {
      arr1.push(x.toString());
    }
   
    funcA = function(array, item) {
      for (var i = 0, len = array.length; i < len; i++)
      if (array[i] === item) return i;
      return -1;
    };
   
    funcB = function(array, item) {
      var t = Object(array);
      var len = t.length >>> 0;
      for (var i = 0; i < len; i++)
      if (i in t && t[i] === item) return i;
      return -1
    };
   
    execute = function(fn) {
      fn(arr1, '0');
      fn(arr1, '49');
    };
};
</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
funcA
execute(funcA);
pending…
funcB
execute(funcB);
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