reg vs str-comp

Benchmark created on


Setup

var str = "汉字汉字123",
        chars = str.split(""),
        chars_count = chars.length;

Test runner

Ready to run.

Testing in
TestOps/sec
re
function reTest() {
        for (var i = 0; i < chars_count; i ++) {
                if (chars[i].match(/[\x00-\xff]/)) {}
        }
}
 
ready
str-comp
function strCompTest() {
        for (var i = 0; i < chars_count; i ++) {
                if (chars[i] <= "\xff") {}
        }
}
 
ready

Revisions

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