Regex Performance Testing (v6)

Revision 6 of this benchmark created on


Description

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

Setup

var preCompiledReplaceRegex = /\b(test|is|a|regex)\b/ig; 
    
    myHtml = "<span>This is a test</span><div>Of a regex</div><p>test</p><em>test</em>";

Test runner

Ready to run.

Testing in
TestOps/sec
Precompiled Regex (Replace)
myHtml.replace(preCompiledReplaceRegex, 'kittens');
ready
Non-Precompiled Regex (Replace)
myHtml.replace(/\b(test|is|a|regex)\b/ig, "kittens");
ready

Revisions

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