inArray vs indexOf (v14)

Revision 14 of this benchmark created by Arka Pratim on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="//underscorejs.org/underscore-min.js">
</script>

Setup

var arr = [];
    for (var i = 0; i < 1000; i++) {
      arr.push(i);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf first
_.indexOf(arr, 0)
ready
indexOf last
_.indexOf(arr, 999)
ready
$.inArray 1st
jQuery.inArray(0, arr)
ready
$.inArray last
jQuery.inArray(999, arr)
ready

Revisions

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