Date YMD: toISOString vs Concat

Benchmark created on


Setup

const data = [...Array(1000).keys()].map((i)=>new Date(1732228545000+i*3600000));
const dateToString = (date) => date.toISOString().substring(0, 10);
function dateToYMD(date) {
  return [
          date.getFullYear(),
          ('0' + (date.getMonth() + 1)).slice(-2),
          ('0' + date.getDate()).slice(-2),
        ].join('-')
}

Test runner

Ready to run.

Testing in
TestOps/sec
const result = data.map(dateToString)
const result = data.map(dateToString)
console.log(result)
ready
const result = data.map(dateToYMD)
const result = data.map(dateToYMD)
console.log(result)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.