Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stringify a Date as number instead of string. #9

Closed
delvedor opened this issue Sep 28, 2016 · 1 comment
Closed

Stringify a Date as number instead of string. #9

delvedor opened this issue Sep 28, 2016 · 1 comment

Comments

@delvedor
Copy link
Member

I did this bench, and the result is remarkable.

'use strict'

const benchmark = require('benchmark')
const suite = new benchmark.Suite()
const date = new Date()

suite
  .add('toISOString()', function () {
    date.toISOString()
  })
  .add('getTime()', function () {
    date.getTime()
  })
  .on('cycle', function (event) {
    console.log(String(event.target))
  })
  .on('complete', function () {})
  .run()

Result:

toISOString() x 2,132,610 ops/sec ±0.84% (91 runs sampled)
getTime() x 86,037,830 ops/sec ±0.96% (92 runs sampled)

Should we move from .toISOString() to .getTime()?

@mcollina
Copy link
Member

No, that would be a violation of the JSON specification. We represent dates as string. Converting them to integers in the schema would be up to the user.

We should document all of this in the README.

BTW, this is why we use Date.now() in pino: pinojs/pino#5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants