my test (v7)

Revision 7 of this benchmark created on


Preparation HTML

<script>
  var elem,
      i = 0,
      allElements = document.getElementsByTagName("*"),
      haystack = [];

  // Sizzle Expr.find["TAG"]
  while ( (elem = allElements[i++]) ) {
    if ( elem.nodeType === 1 ) {
      haystack.push( elem );
    }
  }
</script>

<script>
  var result,
      lowIndex = haystack[2],
      highIndex = haystack[ haystack.length - 2 ],
      notFound = document.body.appendChild( document.createElement("noscript") ),
      myIndexOf = function( elems, elem ) {
        for (var i = 0 ; i < elems.length; i++ ) {
          if ( elems[i] === elem ) {
            return i;
          }
        }
        return -1;
      },
      simpleIndexOf = function( elems, elem ) {
        var i = 0,
        len = elems.length;
        for ( ; i < len; i++ ) {
          if ( elems[i] === elem ) {
            return i;
          }
        }
        return -1;
      };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Low index (mine)
result = myIndexOf.call(haystack, lowIndex);
ready
Low index (thor)
result = simpleIndexOf(haystack, lowIndex);
ready
High index (mine)
result = myIndexOf.call(haystack, highIndex);
ready
High index (thor)
result = simpleIndexOf(haystack, highIndex);
ready
Not found (mine)
result = myIndexOf.call(haystack, notFound);
ready
Not found (thor)
result = simpleIndexOf(haystack, notFound);
ready

Revisions

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