Strings array - in vs indexOf

Benchmark created by Evgeny on


Setup

var a = [];
    
    for (var i = 0; i < 1000; i++)
      a.push(String(1));
    
    var b = ["32", "94234", "1FSDFFsd", "12", "4234235", "a", "999"]
    
    var num = 0;

Teardown


    num = 0;
  

Test runner

Ready to run.

Testing in
TestOps/sec
in
for (var i = 0; i < b.length; b++)
  if (b in a)
    num++;
ready
indexOf
for (var i = 0; i < b.length; b++)
  if (a.indexOf(b) != -1)
    num++;
ready

Revisions

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