array index to string regex of speed check (v2)

Revision 2 of this benchmark created by Dan Beam on


Preparation HTML

<script>
  var a = [],
      four = /four/,
      b, i, pre = "test";
  
  for (i = 0; i < 1000; i++) {
   a.push(pre + i);
  }
  
  b = a.join(' ');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
string regex
/four/.test(a);
ready
array indexOf
b.indexOf("four")
ready
pre-compiled regex
four.test(a);
ready

Revisions

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

  • Revision 2: published by Dan Beam on