Skip to content

improve performance of asNumber #595

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

Merged
merged 1 commit into from
Jan 22, 2023
Merged

improve performance of asNumber #595

merged 1 commit into from
Jan 22, 2023

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Jan 22, 2023

before:

{"n1":1,"n2":null}
number x 43,047,096 ops/sec ±1.45% (183 runs sampled)

after:

node bench
{"n1":1,"n2":null}
number x 1,253,340,543 ops/sec ±0.11% (195 runs sampled)

This is my benchmark:

'use strict'

const Benchmark = require('benchmark')
Benchmark.options.minSamples = 100

const suite = Benchmark.Suite()

const FJS = require('.')
const stringify = FJS({
  type: 'object',
  properties: {
    n1: { type: 'number' },
    n2: { type: 'number' },
  }
})

// const stringify = require('./serialize')

const input = {
  n1: 1,
  n2: Infinity
}
console.log(stringify(input))

suite
  .add('number', () => {
    stringify(input)
  })
  .on('cycle', (event) => {
    console.log(String(event.target))
  })
  .on('complete', () => {})
  .run()

Checklist

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 07a9bcc into master Jan 22, 2023
@Uzlopak Uzlopak deleted the improve-asNumber branch January 22, 2023 23:56
Uzlopak added a commit that referenced this pull request Jan 24, 2023
mcollina added a commit that referenced this pull request Feb 22, 2023
mcollina added a commit that referenced this pull request Feb 22, 2023
* Revert "improve performance of asNumber (#595)"

This reverts commit 07a9bcc.

* add regression test

Signed-off-by: Matteo Collina <[email protected]>

---------

Signed-off-by: Matteo Collina <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants