grep vs pure js

JavaScript performance comparison

Revision 8 of this test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>


      
<script>
Benchmark.prototype.setup = function() {
  var ar = [1,2,3,4,5,6,7,8,9,10] ;
  
  function cond(e){return e == 10}
  
  Array.prototype.filter1 = 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 res = []; var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in t) { var val = t[i]; if (fun.call(thisp, val, i, t)) res.push(val); } } return res; };

};
</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
jQuery
$.grep(ar, cond);
pending…
JS
ar.filter1(cond);
pending…
native Array.filter
ar.filter(cond);
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