Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
String compare with localCompare
string vs localCompare
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser:
Chrome 123
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
Using string comparison
307K/s
localCompare
257K/s
Using collator
86K/s
View exact numbers
Test name
Executions per second
✓
Using string comparison
307,079 Ops/sec
localCompare
256,646 Ops/sec
Using collator
85,909 Ops/sec
Tests:
Using string comparison
const test = ['Sweden', 'Japan', 'New Zealand', 'United States', 'Australia']; test.sort((a,b) => a < b ? -1 : (a > b ? 1 : 0)); console.log(test);
localCompare
const test = ['Sweden', 'Japan', 'New Zealand', 'United States', 'Australia']; test.sort((a,b) => a.localeCompare(b)); console.log(test);
Using collator
const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' }); const test = ['Sweden', 'Japan', 'New Zealand', 'United States', 'Australia']; test.sort((a, b) => collator.compare(a, b)); console.log(test)