Each time I have downloaded a new copy of Rakudo Perl 6, I have run the following expression just to get an idea of its current performance:
say [+] 1 .. 100000;
And the speeds have been increasing, but each time, there is a noticeable delay (several seconds) for the calculation. As a comparison, something like this in Perl 5 (or other interpreted languages) returns almost instantly:
use List::Util 'sum';
print sum(1 .. 100000), "\n";
or in Ruby (also nearly instant):
(1 .. 100000).inject(0) {|sum,x| sum+x}
Rewriting the expression as a Perl6 loop
ends up being about twice as fast as reducing the range, but it is still a very noticeable delay (more than a second) for the simple calculation:
my $sum;
loop (my $x = 1; $x <= 100000; $x++) {$sum += $x}
So my question is, what aspects of the Perl6 implementation are causing these performance issues? And should this improve with time, or is this overhead an unfortunate side effect of the "everything is an object" model that Perl6 is using?
And lastly, what about the loop
construct is faster than the [+]
reduction operator? I would think that the loop would result in more total ops than the reduction.
EDIT:
I'd accept both mortiz
's and hobbs
's answers if I could. That everything is a being handled as a method call more directly answers why [+]
is being slow, so that one gets it.