localeCompare vs custom compare (v19)

Revision 19 of this benchmark created on


Setup

var s1 = "First";
    var s2 = "Second";

Test runner

Ready to run.

Testing in
TestOps/sec
localeCompare
s1.localeCompare(s2)
ready
Custom
s1 < s2 ? -1 : s1 > s2 ? 1 : 0;
ready
Custom
if (s1 < s2) {
  -1;
} else if (s1 > s2) {
  1;
} else {
  0;
}
ready
Custom (toLowerCase)
s1 = s1.toLowerCase();
s2 = s2.toLowerCase();
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.