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; rv:133.0) Gecko/20100101 Firefox/133.0
Browser:
Firefox 133
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
sort
4476587.0 Ops/sec
localcompare
427103.3 Ops/sec
manual compare
2852891.2 Ops/sec
date convert to date + sort a-b (timezone safe)
481481.3 Ops/sec
date convert to timestamp + sort (timezone safe)
467961.4 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();