use strict; use warnings; my $maxprimes=100; my $value=1; my $count=0; my $start=time(); print "Printing the first $maxprimes numbers that are prime... \n"; while ($count < $maxprimes) { my $v = $value++; my $composite; OUTER: for my $i (2..$v) { INNER: for my $j ($i..$v) { if (($j*$i) == $value) { $composite=1;#true last OUTER; } } } if (! $composite) { $count++; print "$value is prime\n"; } } my $time = (time() - $start); print "Took $time seconds.\n";
In reply to Re: performance of perl vs java
by runrig
in thread performance of perl vs java
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |