FYI, for really thorough timing results, check out Devel::NYTProf:
http://search.cpan.org/~timb/Devel-NYTProf-4.03/lib/Devel/NYTProf.pm

You have a lot of things going on to mix up the results - you have both a
memory allocation and a calculation. As I understand it, Perl will likely
outperform PDL in the memory allocation portion of this exercise, but PDL
should have Perl's lunch for the calculation portion.

Perl will outperform PDL in the memory allocation because in all likelihood,
it doesn't perform any allocation with the push. It likely already allocated
more than three elements for (all of) its arrays, so pushing the new value
on the array does not cost anything, except for a higher up-front memory
cost. I suspect this is where PDL is losing to Perl - Perl is performing the
allocation ahead of where you start the timer.

In terms of the calculation itself, PDL should far outperform Perl. The
reason is that the actual contents of the calculation loop are very slim, so
the cost of all of the Perl stack manipulation should significantly increase
its cost. The reason Perl for loops usually make sense are because the code
inside the for loops often involve IO operations or other such things, in
which case the Perl stack manipulations comprise only a small portion of the
total compute time.

Try a situation when Perl and PDL allocate their memory as part of the
timing and see what that gives.

David

-- 
Sent via my carrier pigeon.
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to