$ node -v
v12.8.1
$ node date-performance.js
intl: 3407.266ms
moment: 185.616ms
dayjs: 205.384ms
date-fns: 220.086ms
Last active
August 29, 2019 09:28
-
-
Save koh110/c16c9b9184feacc698bbdbf8b1bc309d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const moment = require('moment') | |
const dayjs = require('dayjs') | |
const { format } = require('date-fns') | |
const limit = 10000 | |
const date = new Date() | |
console.time('intl') | |
for (let i = 0; i < limit; i++) { | |
new Intl.DateTimeFormat('jp', { | |
year: 'numeric', | |
month: 'numeric', | |
day: 'numeric', | |
hour: 'numeric', | |
minute: 'numeric', | |
second: 'numeric', | |
hour12: false | |
}).format(date) | |
} | |
console.timeEnd('intl') | |
console.time('moment') | |
for (let i = 0; i < limit; i++) { | |
moment(date).format('YYYY-M-DD H:mm:ss') | |
} | |
console.timeEnd('moment') | |
console.time('dayjs') | |
for (let i = 0; i < limit; i++) { | |
dayjs(date).format('YYYY-M-DD H:mm:ss') | |
} | |
console.timeEnd('dayjs') | |
console.time('date-fns') | |
for (let i = 0; i < limit; i++) { | |
format(date, 'yyyy-M-dd H:mm:ss') | |
} | |
console.timeEnd('date-fns') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const moment = require('moment') | |
const dayjs = require('dayjs') | |
const { format } = require('date-fns') | |
const limit = 10000 | |
const date = new Date() | |
console.time('intl') | |
const intl = new Intl.DateTimeFormat('jp', { | |
year: 'numeric', | |
month: 'numeric', | |
day: 'numeric', | |
hour: 'numeric', | |
minute: 'numeric', | |
second: 'numeric', | |
hour12: false | |
}) | |
for (let i = 0; i < limit; i++) { | |
intl.format(date) | |
} | |
console.timeEnd('intl') | |
console.time('moment') | |
for (let i = 0; i < limit; i++) { | |
moment(date).format('YYYY-M-DD H:mm:ss') | |
} | |
console.timeEnd('moment') | |
console.time('dayjs') | |
for (let i = 0; i < limit; i++) { | |
dayjs(date).format('YYYY-M-DD H:mm:ss') | |
} | |
console.timeEnd('dayjs') | |
console.time('date-fns') | |
for (let i = 0; i < limit; i++) { | |
format(date, 'yyyy-M-dd H:mm:ss') | |
} | |
console.timeEnd('date-fns') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment