array.some vs loop

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  if (!Array.prototype.some)
  {
  Array.prototype.some = function(fun /*, thisp */ ) {

    "use strict";
  
    if (this == null) throw new TypeError();
  
    var t = Object(this);
    var len = t.length >>> 0;
    if (typeof fun != "function") throw new TypeError();
  
    var thisp = arguments[1];
    for (var i = 0; i < len; i++) {
      if (i in t && fun.call(thisp, t[i], i, t)) return true;
    };
  
    return false;
  };
  };
  var arr = [];
  for (var i; i < 10000; i++) {
    arr.push(i);
  };
  var isBigEnough = function(element, index, array) {
      return (element >= 50);
      };
  var isBigEnough2 = function(element, index, array) {
      return (element >= 9999);
      };
      
  var mySome = function(arr, val) {
      for (var i, ii = arr.length; i< ii; i++) {
        if (arr[i] > val) {
          return true;
        };
      };
      return false;
  };

};
</script>

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
loop (50)
mySome(arr, 50)
pending…
some (50)
arr.some(isBigEnough);
pending…
loop (9999)
mySome(arr, 9999)
pending…
some (9999)
arr.some(isBigEnough2);
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