Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
iso date string sort comparison
compares ways of sorting a list of dates in the form of ISO dates
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/135.0.0.0 Safari/537.36
Browser:
Chrome 135
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
sort
5138477.0 Ops/sec
localcompare
2378864.8 Ops/sec
manual compare
3104322.2 Ops/sec
date convert to date + sort a-b (timezone safe)
285744.0 Ops/sec
date convert to timestamp + sort (timezone safe)
452021.0 Ops/sec
Script Preparation code:
var dates = [ '2021-11-22T11:00:00.000Z', '2021-11-22T07:00:00.000Z', '2021-11-24T12:30:00.000Z', '2021-11-24T07:00:00.000Z', '2021-11-24T07:00:00.000Z', '2021-11-26T07:00:00.000Z', '2021-11-26T12:30:00.000Z', '2021-11-26T12:30:00.000Z', '2021-11-27T11:00:00.000Z', '2021-11-27T12:30:00.000Z', '2021-09-22T11:00:00.000Z', '2021-09-22T07:00:00.000Z', '2021-09-24T12:30:00.000Z', '2021-09-24T07:00:00.000Z', '2021-09-24T07:00:00.000Z', '2021-09-26T07:00:00.000Z', '2021-05-26T12:30:00.000Z', '2021-12-26T12:30:00.000Z', '2021-09-27T11:00:00.000Z', '2021-09-27T12:30:00.000Z', ];
Tests:
sort
const sorted = dates.sort();
localcompare
const sorted = dates.sort((a,b)=>a.localeCompare(b));
manual compare
const sorted = dates.sort(( a, b )=> a < b ? -1 : a > b ? 1 : 0);
date convert to date + sort a-b (timezone safe)
const sorted = dates.map(date=>new Date(date)).sort(( a, b )=> a-b);
date convert to timestamp + sort (timezone safe)
const sorted = dates.map(date=>Date.parse(date)).sort();