Test Array loop with sort method

JavaScript performance comparison

Test case created

Preparation code

<script>
  var myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35];
  var res = 0;

function each(a,f){
  var l=a.length,
      i=l;
  l++;
  while (--l) {
    var b = i-l;
    f(a[b],b);
  }
}

function each2(a,f){
  for(var i=0,l=a.length;i!==l;i++){
    f(a[i],i);
  }
}

</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
Array each
each(myArray, function(v,idx){
  res += v;
});
window.res = res;
pending…
Array each2
each2(myArray, function(v,idx){
  res += v;
});
window.res = res;
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