Regex literal in loop vs Cached

Benchmark created by Ult Combo on


Setup

var str = 'Lorem Ipsum foo Lorem',
        reg = /foo/i;

Test runner

Ready to run.

Testing in
TestOps/sec
literal
for (var i=0; i<10; i++) {
    /foo/i.test(str);
}
ready
cached
for (var i=0; i<10; i++) {
    reg.test(str);
}
ready

Revisions

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

  • Revision 1: published by Ult Combo on