Skip to content

Commit

Permalink
feat(date-format): added more tests cases
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Jan 7, 2023
1 parent b50a73f commit bef059e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions bench/date-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,45 @@ const tableHeader = createTableHeader([
'samples'
])

const localeStringOptions = {
year: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
day: '2-digit',
month: '2-digit',
};

const df = new Intl.DateTimeFormat()
const dfWithOptions = new Intl.DateTimeFormat(undefined, localeStringOptions);

suite.add('Intl.DateTimeFormat().format(Date.now())', function () {
new Intl.DateTimeFormat().format(Date.now())
})
.add('Intl.DateTimeFormat().format(new Date())', function () {
new Intl.DateTimeFormat().format(new Date())
})
.add('Intl.DateTimeFormat(undefined, localeStringOptions).format(Date.now())', function () {
new Intl.DateTimeFormat(undefined, localeStringOptions).format(Date.now())
})
.add('Intl.DateTimeFormat(undefined, localeStringOptions).format(new Date())', function () {
new Intl.DateTimeFormat(undefined, localeStringOptions).format(new Date())
})
.add('Reusing Intl.DateTimeFormat()', function () {
df.format(Date.now())
})
.add('Reusing dfWithOptions.format(Date.now())', function () {
dfWithOptions.format(Date.now())
})
.add('Reusing dfWithOptions.format(new Date())', function () {
dfWithOptions.format(new Date())
})
.add('Date.toLocaleDateString()', function () {
new Date().toLocaleDateString()
})
.add('Date.toLocaleDateString(undefined, localeStringOptions)', function () {
new Date().toLocaleDateString(undefined, localeStringOptions);
})
.add('Format using date.get*', function() {
const date = new Date()
const formated = `${date.getMonth() + 1}/${date.getUTCDate()}/${date.getUTCFullYear()}`
Expand Down

0 comments on commit bef059e

Please sign in to comment.