If you think that discrepancy is impressive you're going to love this. I
added a version to your example using native ints:
https://gist.github.com/LLFourn/8c3e895e789fab957355ce23c9420133

bash-3.2$ perl6 native-int-perf.p6
perl6-loop: 84.8739988
c-loop: 67.65849241 (1.25 times faster)
native-loop: 0.4981954 (135.81 times faster)

(!)

On Sun, Mar 12, 2017 at 2:08 AM Michael Schaap <perl6-bugs-follo...@perl.org>
wrote:

# 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);
}

Reply via email to