HTML Preparation code:
AخA
 
1
<!--your preparation HTML code goes here-->
Script Preparation code:
x
 
const compareString = (a, b) => {
        if (a === null && b !== null) {
            return 1;
        } else if (a !== null && b === null) {
            return -1;
        } else if (a !== null && b !== null) {
            return a.toLowerCase() > b.toLowerCase() ? 1 : a.toLowerCase() === b.toLowerCase() ? 0 : -1;
        } else {
            return 0;
        }
};
const compareString2 = (a, b) => {
        const s1 = a ? [...a.toLowerCase()].reduce((prev, char) => prev + char.charCodeAt(0), 0) : 0;
        const s2 = b ? [...b.toLowerCase()].reduce((prev, char) => prev + char.charCodeAt(0), 0) : 0;
        return a && b ? Math.sign(s1 - s2) : Math.sign(s2 - s1);
};
Tests:
  • compareString()

     
    compareString("Anita", "Ben");
  • compareString2()

     
    compareString2("Anita", "Ben");
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    compareString()
    compareString2()

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one month ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Chrome 132 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
compareString() 30376498.0 Ops/sec
compareString2() 7690405.0 Ops/sec