I haven't analyzed your code in any depth (time constraints, lack of sleep, too many interactions with global variables). But it does appear that you're not taking advantage of some of the advantages of perl to get things going a bit faster.
A couple random notes:
$population = regenrate_population(); ... sub regenrate_population { my $new_population = []; for my $i ( 0 .. ( $population_size - 1 ) ) { my $chromosome1 = get_nonrandom_chromosome(); my $chromosome2 = get_nonrandom_chromosome(); $$new_population[$i] = get_child( $chromosome1, $chromosome2 ) +; } return $new_population; }
and:my $crossover_point = int( rand($chromosome_size) ); for my $i ( 0 .. ( $chromosome_size - 1 ) ) { if ( $i < $crossover_point ) { push( @$new_chromosome, @$chromosome1[$i] ); } else { push( @$new_chromosome, @$chromosome2[$i] ); } }
my $crossover_point = int( rand($chromosome_size) ); $new_chromosome = [ @{$chromosome1}[ 0 .. $crossover_point-1], @{$chromosome2}[ $crossover_point .. $#{$chromosome2} ] ];
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re: Perl slower than java
by roboticus
in thread Perl slower than java
by Christian888
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |