Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Intl.Collator.compare vs String.prototype.localeCompare (v8 ASCII fast path)
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Intl.Collator.compare (ASCII-only strings)
374.9 Ops/sec
String.prototype.localeCompare (ASCII-only strings)
768.6 Ops/sec
Intl.Collator.compare
260.6 Ops/sec
String.prototype.localeCompare
283.4 Ops/sec
Script Preparation code:
function randomStrings(chars, length, stringLength) { const randomChar = () => chars[Math.floor(Math.random() * chars.length)]; const randomString = () => Array.from({length: stringLength}, randomChar).join(""); return Array.from({length}, randomString); } var asciiStrings = randomStrings(["a", "b", "c"], 50000, 9); var unicodeStrings = randomStrings(["간", "쟁", "뜻"], 50000, 9);
Tests:
Intl.Collator.compare (ASCII-only strings)
const collator = new Intl.Collator(); asciiStrings.sort(collator.compare);
String.prototype.localeCompare (ASCII-only strings)
asciiStrings.sort((a, b) => a.localeCompare(b));
Intl.Collator.compare
const collator = new Intl.Collator(); unicodeStrings.sort(collator.compare);
String.prototype.localeCompare
unicodeStrings.sort((a, b) => a.localeCompare(b));