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

fix: faster diff #539

Merged
merged 1 commit into from Apr 7, 2023
Merged

fix: faster diff #539

merged 1 commit into from Apr 7, 2023

Conversation

H4ad
Copy link
Contributor

@H4ad H4ad commented Apr 7, 2023

Based on the comment here: #533 (comment)

The performance before:

diff(0.0.1, 0.0.1-pre) x 310,595 ops/sec ±1.86% (94 runs sampled)
diff(0.0.1, 0.0.1-pre-2) x 317,054 ops/sec ±0.33% (92 runs sampled)
diff(1.1.0, 1.1.0-pre) x 304,229 ops/sec ±1.80% (86 runs sampled)

After:

diff(0.0.1, 0.0.1-pre) x 480,421 ops/sec ±0.86% (96 runs sampled)
diff(0.0.1, 0.0.1-pre-2) x 471,080 ops/sec ±0.99% (94 runs sampled)
diff(1.1.0, 1.1.0-pre) x 476,067 ops/sec ±0.98% (95 runs sampled)
benchmark.js
const Benchmark = require('benchmark')
const diff = require('./functions/diff')
const suite = new Benchmark.Suite()

const cases = [
  ['0.0.1', '0.0.1-pre', 'patch'],
  ['0.0.1', '0.0.1-pre-2', 'patch'],
  ['1.1.0', '1.1.0-pre', 'minor'],
]

for (const [v1, v2] of cases) {
  suite.add(`diff(${v1}, ${v2})`, function () {
    diff(v1, v2)
  })
}

suite
  .on('cycle', function (event) {
    console.log(String(event.target))
  })
  .run({ async: false })

References

@H4ad H4ad requested a review from a team as a code owner April 7, 2023 00:55
@H4ad H4ad requested review from wraithgar and removed request for a team April 7, 2023 00:55
@wraithgar
Copy link
Member

This one is very small and clearly an improvement, so I'm merging it now.

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.

None yet

2 participants