stringvsregex

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

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

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
string
    var newTxt = txt.split('(');
    for (var i = 1; i < newTxt.length; i++) {
        console.log(newTxt[i].split(')')[0]);
    }
pending…
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));
    }
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment