Skip to main content
Code Review

Timeline for Dijkstra path finding in C# is 15x slower than C++ version

Current License: CC BY-SA 4.0

18 events
when toggle format what by license comment
Feb 4, 2020 at 20:20 comment added Oliver Schönrock @JerryCoffin You're welcome. I have added my version of C++ code as a new answer below if you're interested. 5x faster in return for some space cost.
Feb 4, 2020 at 18:40 comment added Jerry Coffin @OliverSchönrock: ah, quite right. Thank you.
Feb 4, 2020 at 18:39 history edited Jerry Coffin CC BY-SA 4.0
edited body
Feb 4, 2020 at 14:29 comment added Oliver Schönrock @JerryCoffin Found the bug: in your contains method. The last condition coord.x < sz should read: coord.z < sz It then gives the same result as OP's C++ code: 37 cell path.
Feb 4, 2020 at 13:32 comment added Oliver Schönrock @JerryCoffin Old thread, but here goes nothing: Treading carefully here, but I think your C++ doesn't produce the same answer the the OP's C++. I am using the provided grid.txt (had to lowwercase it to make it work with C++, and had to add std::boolalpha for reading in the OP's code) His produces a path of 37cells long. Yours produces zero cells long? I am still looking into the reason why. I came across this because I had in mind a simple structural change to apply to both the C++ and the C# which gives a ~5x speedup (in the C++). Then I discovered this discrepancy.
S Jan 21, 2017 at 10:11 history edited Mast CC BY-SA 3.0
edited body
Jan 21, 2017 at 10:07 review Suggested edits
S Jan 21, 2017 at 10:11
Jan 17, 2017 at 18:03 review Low quality posts
Jan 17, 2017 at 18:28
Jan 17, 2017 at 10:54 comment added phuclv reason for not using endl C++: "std::endl" vs "\n"
Jan 16, 2017 at 22:46 comment added Jerry Coffin @Overv: The obvious possibility would be that a cellFilter should do more to reflect the filtering it does, not just the fact that it's doing filtering. Using your example, a SpaceAvailableFilter (or maybe just "EmptyCell", if that's at least reasonably accurate).
Jan 16, 2017 at 17:15 comment added Overv Thanks for your code review, I appreciate your suggestions because some of them also apply to the structure of the C# code. I don't think I can fully switch to C++, because Unity requires me to write at least some C# code to interface with it. Do you have a naming suggestion for cellFilter? The idea is that different objects have different requirements for path finding (e.g. available space, can they fly or walk?).
Jan 16, 2017 at 16:32 history edited Loki Astari CC BY-SA 3.0
deleted 1 character in body
Jan 16, 2017 at 15:56 comment added Jerry Coffin @Christoph: That doesn't seem to me to fall within the realm of reviewing code. I reviewed code. It's up to him to draw conclusions.
Jan 16, 2017 at 15:00 comment added Jerry Coffin @Christoph: Partly out of habit. mordecai154's code improved The C# code's speed a lot--but at least for me, the C++ code is still close to twice as fast. With similar effort in optimizing the C++, its speed can undoubtedly be improved as well, so remaining 5-8x faster than C# looks entirely feasible. In short, he might want to consider throwing away the C# and maintaining the C++.
Jan 16, 2017 at 11:12 comment added t3chb0t @Christoph all code should be readable, no matter whether it's a throw-away or production code, it's a habit and you should always be able to write readable code especially if you're going to show it to others like posting it on CR. This answer doesn't contain any invalid information so downvoting it just for commenting on readability is unfair. A review can include all topics and not necessarily those explicitly requested by OP.
Jan 16, 2017 at 7:42 history edited Jerry Coffin CC BY-SA 3.0
added 8123 characters in body
Jan 16, 2017 at 7:37 history edited Jerry Coffin CC BY-SA 3.0
added 8123 characters in body
Jan 16, 2017 at 7:25 history answered Jerry Coffin CC BY-SA 3.0
toggle format

AltStyle によって変換されたページ (->オリジナル) /