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

perf: improve performance a bit #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

addaleax
Copy link

Use binary search rather than linear sort, since we already
have the ranges array sorted to begin with.

Also, use .splice() directly and avoid removing an element
and then re-introducing others.

Use binary search rather than linear sort, since we already
have the `ranges` array sorted to begin with.

Also, use `.splice()` directly and avoid removing an element
and then re-introducing others.
@bcoe
Copy link
Owner

bcoe commented Sep 19, 2018

@addaleax this looks smart to me. As for our discussion today, I think this algorithm was already a bit broken, and might be fixed with using binary insertion rather than splice.

Should we do this separately? how many cycles do you feel like you have?

@demurgos
Copy link

demurgos commented Sep 20, 2018

This PR results in 20% shorter execution in my experience: merging yargs coverages 100 times goes from 4.7 to 3.85 seconds.

Edit: See #4:

upstream/master:
[email protected] x 23.11 ops/sec ±4.21% (42 runs sampled)
addaleax/improve-performance:
[email protected] x 29.26 ops/sec ±4.19% (51 runs sampled)

@demurgos demurgos mentioned this pull request Sep 20, 2018
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.

3 participants