# New Ticket Created by Michael Schaap # Please include the string: [perl #130982] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/Ticket/Display.html?id=130982 >
Perl6-style simple a-to-b loops are often much slower than the corresponding C-style loops, especially when dealing with embedded loops. My "real life" example (as far as Project Euler is real life) is: http://pastebin.com/SVYAyA5z It takes about 55 seconds on my machine with C-style loops, and about 88 seconds with Perl6-style loops. (Comment the "loop" statements and uncomment the corresponding "for" statements.) A reduced example is at the bottom of this report. It outputs 111.04240975 95.56877319 on my machine. I'm using the latest Rakudo Star, 2017.01. See: https://irclog.perlgeek.de/perl6/2017-03-11#i_14245536 and below. ---------- #!/usr/bin/env perl6 sub perl6-loop($n) { my $start = now; my $sum = 0; for 1..$n -> $i { for 1..$i -> $j { $sum += $i+$j; } } say now - $start; } sub c-loop($n) { my $start = now; my $sum = 0; loop (my $i = 1; $i <= $n; $i++) { loop (my $j = 1; $j <= $i; $j++) { $sum += $i+$j; } } say now - $start; } sub MAIN($n = 10⁴) { perl6-loop($n); c-loop($n); }