toUpperCase vs toLowerCase (v3)

Revision 3 of this benchmark created by remus maximus on


Description

toUpperCase vs toLowerCase I would presume that the non-case changing would be the fastest. since most letters of a string will be lowercase, i would think lower casing a string would be faster then upper casing it.

Setup

var alfaL = "abcdefghijklmnopqrstuvwxyz";
    var alfaLB = "zyxwvutsrqponmlkjihgfedcba";
    var alfaU = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var alfaUB = "ZYXWVUTSRQPONMLKJIHGFEDCBA";
    var str = "ThisIsTheSameLengthStrings";

Test runner

Ready to run.

Testing in
TestOps/sec
Lower to Upper
alfaL.toUpperCase();
alfaLB.toUpperCase();
ready
Upper to Lower
alfaU.toLowerCase();
alfaUB.toLowerCase();
ready
Lower to Lower
alfaL.toLowerCase();
alfaLB.toLowerCase();
ready
Upper to Upper
alfaU.toUpperCase();
alfaUB.toUpperCase();
ready
One of Each
alfaL.toUpperCase();
alfaU.toLowerCase();
ready
string to Lower
str.toLowerCase()
str.toLowerCase()
ready
string to Upper
str.toUpperCase()
str.toUpperCase()
ready

Revisions

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

  • Revision 3: published by remus maximus on