DillonYu has asked for the wisdom of the Perl Monks concerning the following question:
hello every one !
Recently I write a perl script which not long, but it has an array named "@arr_abundant" which contain nearly 30000 elements.
And I make two "for loop" on it on a section
So every time I re run this script, it runs very slowly.
Is there any one can tell me any clues about deal with this problem? such as any cache mechanism. so I can re run it fast for debug?
Really appreciate your help!!
my @arr_abundant; for (12 .. 28123 ){ ### Evaluating [===| ] % done push @arr_abundant, $_ if prob23_type_of_number($_) eq "abundant" + ; } my %hash; # get no repeated abundant number foreach my $i (@arr_abundant){ ### Evaluating [===| ] % done foreach my $j (@arr_abundant) { my $positive = $i + $j; next if $positive > 28123; $hash{$positive} ++; } } # get the sum of positive integers cannot be written as ... my $sum_total; my @arr_sum_two_abundant_numbers=sort {$a <=> $b} keys %hash ; my $n = 1; foreach my $key (@arr_sum_two_abundant_numbers){ for ( my $i=$n ; $i < $key ; $i++) { $sum_total += $i; } $n = $key +1; } print "$sum_total\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Is there any cache mechanism for running perl script
by haukex (Archbishop) on Apr 09, 2017 at 09:33 UTC | |
by DillonYu (Novice) on Apr 18, 2017 at 13:15 UTC | |
Re: Is there any cache mechanism for running perl script
by huck (Prior) on Apr 09, 2017 at 09:42 UTC | |
by Discipulus (Canon) on Apr 12, 2017 at 19:54 UTC | |
by DillonYu (Novice) on Apr 18, 2017 at 13:16 UTC |