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/605.1.15 (KHTML, like Gecko) Version/17.1.2 Safari/605.1.15
Browser:
Safari 17
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
sort
394783.9 Ops/sec
localcompare
470501.7 Ops/sec
manual compare
314725.1 Ops/sec
date convert to date + sort a-b (timezone safe)
56486.5 Ops/sec
date convert to timestamp + sort (timezone safe)
100344.2 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();