Find Array Value

JavaScript performance comparison

Revision 4 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var validChars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
          checkFor = 'n';
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
For Loop
for (i = 0; i < validChars.length; i++)
if (validChars[i] == checkFor) return i;
pending…
For Loop B
for (i = validChars.length; i >= 0; i--)
if (validChars[i] == checkFor) return i;
pending…
For Each
for (i in validChars)
if (validChars[i] == checkFor) return i;
pending…
IndexOf
return validChars.indexOf(checkFor);
pending…
While Loop
i = validChars.length;
while( i-- )
  if( validChars[i] == checkFor ) return i;
pending…
While Loop F
l = validChars.length, i = 0;
while( i++ < l )
  if( validChars[i] == checkFor ) return i;
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:

0 comments

Add a comment