Stories
Slash Boxes
Comments
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Your bintree.pl uses string equality ("eq") rather than numeric equality ("==") for x. This introduces overhead of stringification on every recursion step.
    • 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);
      }