stringvsregex (v11)

Revision 11 of this benchmark created by kyle hamilton on


Description

replace with callback

Preparation HTML

<script>var txt = "I expect five hundred dollars ($500). and new brackets ($600)";</script>

Test runner

Ready to run.

Testing in
TestOps/sec
string
    var newTxt = txt.split('(');
    for (var i = 1; i < newTxt.length; i++) {
        console.log(newTxt[i].split(')')[0]);
    }
ready
regex
var regExp = /\(([^)]+)\)/g;
var matches = txt.match(regExp);
    for (var i = 0; i < matches.length; i++) {
        var str = matches[i];
        console.log(str.substring(1, str.length - 1));
    }
ready
replace with callback
txt.replace(/\(([^)]+)\)/g, function(m, group) { 
    console.log(group)
})
ready

Revisions

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