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
Is jQuery.isArray comparably fast to obj instanceof Array?
EDIT: added a couple of methods I picked up a while back which are more robust than instanceof in special cases.
The problem is, you cannot reliably test for arrays using instanceof. The following check returns false: ((new Array) instanceof Array)
While the following returns true: ((new Array) instanceof Object)
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
function jq_array() {
return jQuery.isArray([]);
}
function instof() {
return ([] instanceof Array);
}
function constr() {
return ([].constructor == Array);
}
function tostringcall() {
Object.prototype.toString.call([]) === '[object Array]';
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
jQuery |
| ready |
instanceof |
| ready |
constructor |
| ready |
toString.call |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.