NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

smash (7262)

smash
(email not shown publicly)

Journal of smash (7262)

Sunday April 13, 2008
12:21 PM

Parrot benchmarking, introducing recursion

[ #36140 ]

Recursion is a very common technique used in today's programs. Although recursion is a very easy method to solve problems, it can easily introduce unwanted overhead that can quickly worsen program's performance.

The facts,
1) We created a recursive function to calculate the number of nodes in a full binary tree, given as argument the tree's height.
2) We implemented this function in Parrot, and also on interpreted and compiled languges.
3) We ran the programs several times increasing the height of the tree.

Here are the results: http://nrc.homelinux.org/parrot/bintree.png.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.

Full
Abbreviated
Hidden
• sources?(Score:1)

Is there a way we could see the source(s) being used?

Pm
• bintree.pl eq(Score:1)

Your bintree.pl uses string equality ("eq") rather than numeric equality ("==") for x. This introduces overhead of stringification on every recursion step.
• Re:(Score:1)

I cleaned up n_of_nodes as follows and achieved a 20% speedup for the Perl version. Most of the speedup came from changing "eq" to "==" but interestingly using a ternary instead of an if-else helped too. That is probably because I removed a "return" statement in the process.

sub n_of_nodes {
my (\$x) = @_;
return \$x == 0 ? 1 : 1 + n_of_nodes(\$x-1) + n_of_nodes(\$x-1);
}