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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |