dojo forEach vs. native forEach

JavaScript performance comparison

Revision 11 of this test case created by Martin

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js">
</script>
<script>
  var dojoArray;
  require(["dojo/_base/array"], function(array) {
    window.dojoArray = array;
  });
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var arr = new Array(1000);
  
  function func(item, index, arr) {
    //do nothing
    return item;
  }

};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
dojo forEach
(function anon1() {
  dojoArray.forEach(arr, func);
}());
pending…
Array forEach
(function anon2() {
  arr.forEach(func);
}());
pending…
Native for loop
(function anon3() {
  var i, l;
  for (i = 0, l = arr.length; i < l; i++) {
    func(arr[i], i, arr);
  }
}());
pending…
Native while loop
(function anon4() {
  var i = 0, l = arr.length;
  while(i<l){
    func(arr[i], i++, arr);
  }
}());
pending…
Native reverse while loop
(function anon5() {
  var i = arr.length;
  while(i--){
    func(arr[i], i, arr);
  }
}());
pending…
Native reverse while loop 2
(function anon5() {
  var i = arr.length;
  while(--i > -1){
    func(arr[i], i, arr);
  }
}());
pending…
Native for loop 2
(function anon6() {
  var i = 0, l = arr.length;
  for (; i < l; ++i) {
    func(arr[i], i, arr);
  }
}());
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.

0 Comments