uc_words (v2)

Revision 2 of this benchmark created on


Description

Which is faster?

Setup

var str="hElLo wORlD!";

Test runner

Ready to run.

Testing in
TestOps/sec
slice
function uc_words(str){
        return str.replace(/\S+/g, function(a){
        return a.charAt(0).toUpperCase() + a.slice(1).toLowerCase();
    });
}
ready
substr
function uc_words(str){
        return str.replace(/\S+/g, function(a){
        return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
    });
}
ready
slice + alt regex
function uc_words(str){
        return str.replace(/\w+/g, function(a){
        return a.charAt(0).toUpperCase() + a.slice(1).toLowerCase();
    });
}
ready
substr + alt regex
function uc_words(str){
        return str.replace(/\w+/g, function(a){
        return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
    });
}
ready

Revisions

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