http://www.perlmonks.org?node_id=868151


in reply to Re: Finding All Paths From a Graph From a Given Source and End Node
in thread Finding All Paths From a Graph From a Given Source and End Node

I tried to benchmark your subs (together with my ones - Update: that turned out to be slower). The short circuiting approach is slower than the previous one.
  • Comment on Re^2: Finding All Paths From a Graph From a Given Source and End Node

Replies are listed 'Best First'.
Re^3: Finding All Paths From a Graph From a Given Source and End Node
by Limbic~Region (Chancellor) on Oct 28, 2010 at 21:30 UTC
    choroba,
    The short circuiting approach is slower than the previous one

    I suspect this will heavily depend on the test data which neversaint hasn't supplied. In a nutshell, I am recording path information on the basis that it will pay off down the road. If there is no short circuit possibilities then the overhead of tracking will not be paid for and it becomes slower.

    This is why I said I was unhappy with it. I am going to let this sit in my feeble brain for a while and if I can't come up with a better approach I will post a new thread for other monks to weigh in on.

    Update: The following is the basically the same algorithm with some optimizations. I would be interested in your test data and/or your benchmark.

    Cheers - L~R

      Here is my code as it is (your subs removed):
      Using your graph and R=>P as the path, the short circuit is the best:
      Rate breadth limbic depth limbic_sc breadth 158/s -- -34% -42% -60% limbic 238/s 51% -- -13% -39% depth 274/s 73% 15% -- -30% limbic_sc 392/s 148% 65% 43% --
        choroba,
        As I indicated before, certain graphs, order of traversal and endpoints will determine how well the short circuiting approach fairs. I have asked for advice concerning this at Short Circuiting DFS Graph Traversal. My fastest normal solution is below.

        Cheers - L~R