Rakudo
I noticed the news where Larry Wall have a talk about Perl 6 speaking that it is going to be ready for production use before next Christmas. Well, maybe it’s time to have a dip of Perl 6, after such a long time of sixteen years development.
Building Rakudo on Mac OS X
There does exist Homebrew formula for Rakudo, however, it is bit of outdated as the time of writing. I decided to fetch the latest source from the official site. It turned out it is not hard to get ie built on OS X.
wget “http://rakudo.org/downloads/star/rakudo-star-2014.12.1.tar.gz”
tar zxvf rakudo-star-2014.12.1.tar.gz
cd rakudo-star-2014.12.1/
perl Configure.pl --gen-parrot --gen-moar --gen-nqp --backends=parrot,jvm,moar
make
make install
Speed
I am aware that rakudo comes with different backends, but it is just MoarVM that is going to be marked with green light. To have an idea about its speed, I wrote memoize version of Fibonacci number in rakudo and ruby 2.1.2 respectively. The programs are as follows:
my @memoize;
sub fib(Int $n) {
if $n == 0 || $n == 1 {
return 1;
} else {
if defined @memoize[$n] {
return @memoize[$n];
} else {
@memoize[$n] = fib($n - 1) + fib($n - 2);
return @memoize[$n];
}
}
}
say fib(1000);
$memoize = Array.new(100002)
def fib(n)
if n == 0 or n == 1
return 1
else
if $memoize[n] != nil
return $memoize[n]
else
$memoize[n] = fib(n-1) + fib(n-2)
return $memoize[n]
end
end
end
puts fib(1000)
An simplest time command shows that rakudo is far more slower than ruby. In my opinion ruby implementation has been slow, but rakudo is even slower. For this level of speed I would keep it on my hobby language watching list for another while.
➜ rakudo-star-2014.12.1 time ruby fib.rb
70330367711422815821835254877183549770181269836358732742604905087154537118196933579742249494562611733487750449241765991088186363265450223647106012053374121273867339111198139373125598767690091902245245323403501
ruby fib.rb 0.04s user 0.01s system 92% cpu 0.056 total
➜ rakudo-star-2014.12.1 time ./perl6 fib.pl
70330367711422815821835254877183549770181269836358732742604905087154537118196933579742249494562611733487750449241765991088186363265450223647106012053374121273867339111198139373125598767690091902245245323403501
./perl6 fib.pl 0.81s user 0.21s system 98% cpu 1.035 total