Using a for loop
my $N = 100000; my $N = 100000; my $i = 0; my $i = 0; my $j = 0; # start timer # start timer while $j < $N { for 0..^$N -> $j { $i = $i + $j; $i = $i + $j; $j = $j + 1; } } # stop timer # stop timer
Results (seconds):
2011.01 while 0..^N 23.04 for 0..^N 34.93 startup 0.62 ☹ ☹ ☹ ☹ ☹