compute regex vs substr (v7)

Revision 7 of this benchmark created on


Description

http://stackoverflow.com/questions/11818896/how-do-i-make-an-anchored-regex-match-in-the-middle-of-a-string-in-javascript (edit 1) bugfix: don't substr in case 1. The RegExp moves the starting position.

Setup

var target = "foobar barse";
    
    var str_match = "bar";
    var pre_regex = /^bar/;

Test runner

Ready to run.

Testing in
TestOps/sec
compute
for (var i = 0; i < 10; i++) 
    new RegExp("^[\\S\\s]{" + i + "}" + str_match).test(target);
ready
substr+pre
for (var i = 0; i < 10; i++) 
    pre_regex.test(target.substr(i));
ready

Revisions

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