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; Ubuntu; Linux x86_64; rv:134.0) Gecko/20100101 Firefox/134.0
Browser:
Firefox 134
Operating system:
Ubuntu
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
localeCompare
3767258.2 Ops/sec
compare
14080657.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");