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
Theory: Array.filter() will be faster than nested jQuery.grep() when using arrays of integers
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
// jquery grep functionized
if (!Array.prototype.subtractSet) {
Array.prototype.subtractSet = function (set, key) {
return $.grep(this, function (a) {
return $.grep(set, function (b) {
return key ? b[key] === a[key] : a === b;
}).length == 0;
});
}
}
// the following code courtesy Andy @ Stack Overflow
// pass in an array and the key for which you want values
// it returns an array of those values
function getValues(arr, key) {
return arr.map(function (el) { return el[key]; });
}
if (!Array.prototype.notFoundIn) {
Array.prototype.notFoundIn = function (inThisArray, key) {
var thisArr = key ? getValues(this, key) : this;
var arrIn = key ? getValues(inThisArray, key) : inThisArray;
return thisArr.filter(function (el) {
return arrIn.indexOf(el) === -1;
});
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
nested jQuery.grep() |
| ready |
mapped Array.filter() (not mapped in this case) |
| ready |
jQuery.grep() subtract set |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.