When the first version of Rakudo Star came out, I was eager to try it, but I was, erm, somewhat underwhelmed by the fact that its performance was not quite up to what some people might have expected:
$ time ./perl6 -e 'my $s; for 1..10000 {$s+=1/$_**2};say $s'
1.64483407184806
real 0m38.387s
user 0m38.154s
sys 0m0.232s
$ time perl -E 'my $s; for (1..10000) {$s+=1/$_**2};say $s'
1.64483407184806
real 0m0.009s
user 0m0.008s
sys 0m0.004s
One year later, I've tried the same "benchmark" with Rakudo Star 2011.07:
time ./perl6 -e 'my $s; for 1..10000 {$s+=1/$_**2};say $s'
1.64483407184806
real 0m9.588s
user 0m9.513s
sys 0m0.068s
Well, it's an improvement.
Now, the latest version (2012.01) came out, supposedly with great improvements, so I thought I'd try it.
To my great consternation the same script didn't complete within three minutes. I tried to lower the loop range:
time ./perl6 -e 'my $s; for 1..1000 {$s+=1/$_**2};say $s'
NaN
real 0m2.164s
user 0m2.080s
sys 0m0.080s
Note that the result is incorrect (it is a number actually).
I've tried other ranges:
n of iter | result | time |
200 | 1.63994654685319 | 0.799 |
400 | NaN | 0.937 |
600 | NaN | 1.195 |
800 | NaN | 1.592 |
1000 | NaN | 2.179 |
1200 | NaN | 2.972 |
A very pronounced O(N2) trend can be observed here. Is this a known problem? Because it is a problem: there is nothing in the algorithm that would imply such a quadratic behavior, and indeed, with Rakudo 2011.07, elapsed time grows linearly with the number of iterations.
As to the NaN,
./perl6 -e 'my $s; for 1..358 {$s+=1/$_**2};say $s'
1.64214466837792
./perl6 -e 'my $s; for 1..359 {$s+=1/$_**2};say $s'
NaN
To paraphrase a certain presentation about weird programming languages that's become popular lately,
WAT
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.