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

Make ShortestPath faster #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

amwolff
Copy link

@amwolff amwolff commented Oct 30, 2019

I noticed that the performance of ShortestPath can be substantially improved. Instead of finding all the shortest paths from the initial vertex, we could terminate the search as soon as we found the path to the destination vertex.

I've opened a pull request because I already have a patch.

  1. No API changes whatsoever;
  2. This performance enhancement is based on the original E. W. Dijkstra's paper (it's what should be found in a CS textbook).

old/new comparison:

benchmark                       old ns/op     new ns/op     delta
BenchmarkShortestPath250-4      55089         31078         -43.59%
BenchmarkShortestPath500-4      121956        51563         -57.72%
BenchmarkShortestPath1000-4     206507        79512         -61.50%

@korthaj
Copy link
Member

korthaj commented Oct 31, 2019 via email

@amwolff
Copy link
Author

amwolff commented Nov 3, 2019

No problem! Let me know if you happen to have any questions regarding the patch.

@amwolff
Copy link
Author

amwolff commented Aug 27, 2020

I was going through my old contributions and realized I made a mistake here in the comment about ShortestPath (it should be kept original). I've fixed this in case this may get merged. :)

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