jquery grep vs JS vs underscore without (v16)

Revision 16 of this benchmark created on


Preparation HTML

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

<script src="http://underscorejs.org/underscore-min.js"></script>

Setup

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; };

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery
$.grep(ar, cond);
 
ready
JS
ar.filter1(cond);
ready
native Array.filter
ar.filter(cond);
 
ready
Underscore filter
_.filter(ar, cond)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.