in reply to speed : obj vs func, by_name vs positional

obj_internal would be better rewritten as:

sub obj_internal { my $self = shift; return $self->{arg1} + $self->{arg2} }

Using strictures (use strict; use warnings;) would have alerted you to the issue as would printing the results returned from each test routine:

print param(1, 2), "\n"; print named_param(arg1 => 1,arg2 => 2), "\n"; print $obj->obj_internal(), "\n"; print $obj->obj_pos_param(1, 2), "\n"; print $obj->obj_named_param(arg1 => 1,arg2 => 2), "\n";

That aside (the results for the fixed benchmark are comparable with the original results), the interesting thing here is how little extra overhead in absolute time is added when using the more robust pass by name in an object context. It would be rare indeed that the run time difference is important. The advantage in terms of time for design and maintenance far outweigh any minor run time improvement.

A nice confirmation of the mantras: "Don't prematurely optimize" and "Don't micro-optimize".


DWIM is Perl's answer to Gödel