Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
localeCompare vs charCodeAt
localeCompare vs charCodeAt
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Browser:
Chrome 132
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
localeCompare
46564596.0 Ops/sec
compare
48667376.0 Ops/sec
Script Preparation code:
function localeCompare(a, b) { return a.localeCompare(b); } function compare(a, b) { const aLength = a.length; const bLength = b.length; for (let i = 0; i < bLength; ++i) { let code = a.charCodeAt(i); if (isNaN(code)) { // b startsWith a return -1; } code -= b.charCodeAt(i); if (code) return code; } // a startsWith b return aLength > bLength ? 1 : 0; }
Tests:
localeCompare
localeCompare("radiogQe8_7yhdY4Cl1QQSAsEJocXvTjlCzDN", "radioradioAu5NNprfgPH94MDcxL-rElEcHDvmG");
compare
compare("radiogQe8_7yhdY4Cl1QQSAsEJocXvTjlCzDN", "radioradioAu5NNprfgPH94MDcxL-rElEcHDvmG");