localeCompare (v28)

Revision 28 of this benchmark created by Thor Hanks on


Setup

var s1 = "first";
    var s2 = "second";

Test runner

Ready to run.

Testing in
TestOps/sec
localeCompare
s1.localeCompare(s2)
ready
Custom
compareString(s1, s2);

function compareString(str1, str2) {
        var l1 = str1.length;
        var l2 = str2.length;
        var min = l1 > l2 ? l2 : l1;
        var res = 0, i = 0;
        while(res == 0 && i < min) {
                c1 = str1.charCodeAt(i);
                c2 = str2.charCodeAt(i);
                if(c1 >= 65 && c1 <= 90)
                        c1+=32;
                        if(c2 >= 65 && c2 <= 90)
                        c2+=32;
                        var res = c1 - c2;
                        i++;
        }
        if(res != 0 )
                return res;
                else
                        return l1 - l2;                 
    
    }
 
ready
Custom 2
s1 < s2 ? -1 : s1 > s2 ? 1 : 0;
ready

Revisions

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