What about a native perl6 range loop? Couldn't there be some way for Perl 6 /
Rakudo to generate code competitive on a small range with the "native-loop"
example?
perl6 -e '
{
my int ($a, $one, $three) = (42, 1, 3);
for ^10_000_000 { $a += $one + $a%$three };
say now - ENTER now;
say $a
}
{
# 50% slower with loop invariant $limit
my int ($a, $one, $three) = (42, 1, 3);
my int $limit = 10_000_000; # my removing "int" does not effect perf
for ^$limit { $a += $one + $a%$three };
say now - ENTER now;
say $a
}
{
my int ($a, $one, $three, $limit) = (42, 1, 3, 10_000_000);
loop (my int $i = 0; $i < $limit; $i++) { $a += $one + $a%$three };
say now - ENTER now;
say $a
}'
...program prints...
2.10023098 # perl6 loop
15000042
3.2119384 # attempt at native perl 6 loop
15000042
0.7915038 # native loop
15000042