Skip to content

Commit

Permalink
Add a tweak of perl6/007/01.pl that uses typed variables
Browse files Browse the repository at this point in the history
from #perl6 on 24. July 2009

<pmichaud_> while it seems like having a typed variable would make things faster --
in Rakudo it actually will tend to slow things down slightly (because of the need to check the types)
<pmichaud_> eventually when we have some type-based optimizations in place, that probably won't be the case.
  • Loading branch information
leto committed Jul 25, 2009
1 parent c23385c commit a537d01
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions perl6/007/02.pl
@@ -0,0 +1,24 @@
# This uses typed variables to see the speed impact, otherwise the same as 01

my Int $prime_cnt = 2;
my Int $i = 3;
while ( $prime_cnt < 10001 ) {
$i += 2;
if ( is_prime($i) ) {
$prime_cnt++;
#say "$i is prime ($prime_cnt)";
}
}
say $i;


sub is_prime( Int $n) {

my $x = 3;
while ( $x <= sqrt $n ) {
return 0 unless $n % $x;
$x += 2;
}

return 1;
}

0 comments on commit a537d01

Please sign in to comment.