-
-
Save hinrik/7cf05941c6b32d667c39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <0.1 sec (Perl5) | |
#sub fast { | |
# my @products; | |
# for (my $i = 1; $i <= 999; $i++) { | |
# for (my $n = $i; $n <= 999; $n++) { | |
# push @products, $i * $n; | |
# } | |
# } | |
# return \@products; | |
#} | |
# 1.6 sec | |
sub slow { | |
my @products; | |
loop (my $i = 100; $i <= 999; $i++) { | |
loop (my $n = $i; $n <= 999; $n++) { | |
@products.push: $i * $n; | |
} | |
} | |
return @products; | |
} | |
# 1.7 sec | |
sub slower { | |
my @products; | |
for 100..999 -> $i { | |
for $i..999 -> $n { | |
@products.push: $i * $n; | |
} | |
} | |
return @products; | |
} | |
# 3.7 sec | |
sub slowest { | |
return gather for 100..999 -> $i { | |
take $i * $_ for $i..999; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment