inarraytest
JavaScript performance comparison
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
var arr=[0,1,2,3,4,5,6,7,8,9];
function arrayLoop(elem, array, i) {
var len = array.length;
i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
for ( ; i < len; i++ ) {
// Skip accessing in sparse arrays
if ( i in array && array[ i ] === elem ) {
return i;
}
}
return -1;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
jQuery.inArray last |
|
pending… |
arrayLoop last |
|
pending… |
jQuery.inArray middle |
|
pending… |
arrayLoop middle |
|
pending… |
jQuery.inArray first |
|
pending… |
arrayLoop first |
|
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. Here’s a list of current revisions for this page:
- Revision 1: published
- Revision 2: published by T.J. Crowder
- Revision 3: published by T.J. Crowder
- Revision 4: published
- Revision 5: published
0 comments