I also ran both versions as posted. Using: prompt>perl -d:Profile gene.pl. The profiler is a handy tool for performance analysis. Default output goes to a file, prof.out.

The OO version did 22,144 function calls vs 30,339 for the procedural version. I could not get the code to produce the same results, even with fiddling with the starting params (srand seed, $target, etc). So there is no basis for doing an "apples to apples" comparison.

I did not notice any "accelerate" behavior. The time for each iteration varies because of the random variables. Some iterations are faster than others, but otherwise I saw no pattern to the results. Note that the "clock time" can vary considerably depending upon whatever else besides your program is executing on the machine.

Oh, to "hide" the code to make the post shorter, use <readmore></readmore> tags like I did below.

click on next link for abbreviated prof.out results...

The procedure version:...... perl -d:Profile gene.pl time elapsed (wall): 7.1714 time running program: 6.8431 (95.42%) time profiling (est.): 0.3283 (4.58%) number of calls: 30339 %Time Sec. #calls sec/call F name 54.91 3.7577 5050 0.000744 main::get_phenotype 18.46 1.2631 9898 0.000128 main::get_nonrandom_chromosom +e 9.73 0.6659 5050 0.000132 main::get_result 9.46 0.6476 50 0.012951 main::regenrate_population 4.47 0.3059 4949 0.000062 main::get_child 1.46 0.0999 0 0.099872 * <other> 0.65 0.0444 5050 0.000009 main::get_fitness_score 0.31 0.0213 1 0.021325 <anon>:gene.pl:5 0.19 0.0127 49 0.000260 main::get_population_fitness_ +score 0.14 0.0094 50 0.000188 main::check_for_winner ..... blah ... The OO version ...... time elapsed (wall): 5.5812 time running program: 5.3301 (95.50%) time profiling (est.): 0.2510 (4.50%) number of calls: 22144 %Time Sec. #calls sec/call F name 54.70 2.9155 3672 0.000794 Chromosome::get_phenotype 14.75 0.7864 7144 0.000110 Population::get_nonrandom_chr +omosome 13.19 0.7031 3572 0.000197 Chromosome::new_from 9.25 0.4931 3672 0.000134 Chromosome::get_result 5.12 0.2732 47 0.005812 Population::regenerate 1.06 0.0566 3672 0.000015 Chromosome::get_fitness_score 0.81 0.0430 0 0.043012 * <other> .... blah ...

In reply to Re: Procedural Perl slower than OO Perl!!! by Marshall
in thread Procedural Perl slower than OO Perl!!! by Christian888

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.