indexOf vs RegExes

Benchmark created by bracket on


Setup

var arr = [], str;
    for (var i=0; i < 100; i++) arr.push(i);
    str = arr.join(' ');
    
    var regex1 = /(^|\s)1(\s|$)/;
    var regex50 = /(^|\s)50(\s|$)/;
    var regex99 = /(^|\s)99(\s|$)/;

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf
arr.indexOf(1);
arr.indexOf(50);
arr.indexOf(99);
ready
RegExp
regex1.test(str);
regex50.test(str);
regex99.test(str);
ready

Revisions

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

  • Revision 1: published by bracket on