Regex Performance Testing (v4)

Revision 4 of this benchmark created by erosman on


Description

How much faster is a precompiled regex vs a non-precompiled regex?

Setup

var preCompiledReplaceRegex = /test/;
    
    myHtml = "<span>This is a test</span><div>Of a regex</div><p>test</p><em>test</em>";
    
    
    //erosman: testing new RegExp()
    var thisRegExp = new RegExp('test', '')

Test runner

Ready to run.

Testing in
TestOps/sec
Precompiled Regex (Replace)
preCompiledReplaceRegex.test(myHtml);
ready
Non-Precompiled Regex (Replace)
/test/.test(myHtml);
ready
Precompiled New RegExp()
//erosman: testing new RegExp()
thisRegExp.test(myHtml);
ready

Revisions

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