Skip to content

Fix Issue 15553 - topN very inefficient [slower than sort, even for topN(0)] but should be O(n) #3921

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 6 commits into from
Jan 13, 2016

Conversation

andralex
Copy link
Member

  • Replace random selection with getPivot, which is also used by sort.
  • Use a local copy instead of swapping range elements around when possible
  • Special-case n==0, which may be either requested from the beginning or occur naturally toward the end of the search.

@andralex
Copy link
Member Author

While at it I've also improved performance of partition (which topN uses) to use indexing for arrays.

@andralex
Copy link
Member Author

Ugh, I ran make std.algorithm.sorting.test instead of make std/algorithm/sorting.test and it looked like it's working. We should improve our pattern matching...

@andralex
Copy link
Member Author

minPos is now also faster for certain ranges.

@JackStouffer
Copy link
Contributor

We should improve our pattern matching...

You mean humans'? ;)

@9il
Copy link
Member

9il commented Jan 12, 2016

LGTM


For ndslice example (see also update #3925)

  • 3x3 blocks: the new topN 90% faster than old topN and 10% slower than sort
  • 7x7 blocks: the new topN 110% faster than old topN and 10% faster than sort

@andralex
Copy link
Member Author

@9il I just invited you to the team, I guess passing a library through the review process was testing enough. You'll have the right to pull if you accept the invite. Thanks!

@9il
Copy link
Member

9il commented Jan 12, 2016

@andralex Accepted. Thank you!

@andralex
Copy link
Member Author

ping - including @9il :)

9il added a commit that referenced this pull request Jan 13, 2016
Fix Issue 15553 - topN very inefficient [slower than sort, even for topN(0)] but should be O(n)
@9il 9il merged commit 10da338 into dlang:master Jan 13, 2016
@9il
Copy link
Member

9il commented Jan 13, 2016

ping - including @9il :)

How can I turn on AutoMerge next time?

@andralex
Copy link
Member Author

@9il click on the "details" link by the "auto-tester", create an account, and then you can use the "Toggle" link in there.

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