in reply to Re^12: Parallel::ForkManager is time consuming...takes too long
in thread Parallel::ForkManager is time consuming...takes too long

thank you! I will implement the suggestions. I am sure that will improve the speed. Last question: Is this necessary my $b = $b[$i];?

Replies are listed 'Best First'.
Re^14: Parallel::ForkManager is time consuming...takes too long
by BrowserUk (Patriarch) on Aug 17, 2011 at 23:23 UTC
    Is this necessary my $b = $b[$i];?

    Strictly necessary for function, no. Quicker and clearer, yes.

    Like a bookmark (or locking a tab) for a page you reference frequently. Perl is not so good as statically compiled languages at sub-expression elimination.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^14: Parallel::ForkManager is time consuming...takes too long
by ikegami (Patriarch) on Aug 17, 2011 at 23:35 UTC

    He added

    <#> gv[*b] s # my $b = $b[$i]; <1> rv2av sKR/1 <0> padsv[$i:2,4] s <2> aelem sK/2 <0> padsv[$b:3,4] sRM*/LVINTRO <2> sassign vKS/2

    in order to replace a large number of

    <#> gv[*b] s # $b[$i] <1> rv2av sKR/1 <0> padsv[$i:2,3] s <2> aelem sK/2

    with

    <0> padsv[$b:3,4] s # $b

    Assuming each of these ops take roughly the same amount of time to execute, this adds up. Basically,

    my $b = $b[$i]; ... $b ... $b ... $b # 6 + 1*3 = 9 ops

    is faster than

    $b[$i] ... $b[$i] ... $b[$i]; # 0 + 4*3 = 12 ops

    Since his code looks up $b[i] 4 to 8 times (depending on the value of $b[$i]), this saves 6 to 18 ops. Per loop pass!