jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Comparing jQuery.grep to native Array.filter when looping over an array.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
(function($){
// Only check for the existance of Array.filter once
var filterExists = $.isFunction(Array.prototype.filter);
$.newGrep = function(collection, callback, invert){
// If this is an array, and Array.filter exists, use it rather than the existing jQuery.grep
if (filterExists && ($.type(collection) === 'array')) {
invert = (invert === true);
return collection.filter(function(item, index){
return (callback(item, index) !== invert);
});
}
return $.grep(collection, callback);
};
})(jQuery);
var arrOfNums= [];
for (var i=0;i<1000;i++) {
arrOfNums.push(Math.random());
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
jQuery.grep |
| ready |
jQuery.grep with Array.filter |
| ready |
Array.filter |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.