in reply to Re^2: Preferred technique for named subroutine parameters?
in thread Preferred technique for named subroutine parameters?

My benchmark foo is very poor but does this show that if you do something with the arguments the "waste" is not as dramatic as your figures show?
#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); sub f{ my %hash = @_; my $value = $hash{foo}; } sub g{ my $hash_ref = shift; my $value = $hash_ref->{foo} } cmpthese ( -1 => { list => sub { f( foo => 1) }, ref => sub { g({foo => 1})}, } ); __END__ Rate ref list ref 693652/s -- -25% list 919951/s 33% --

Replies are listed 'Best First'.
Re^4: Preferred technique for named subroutine parameters?
by shmem (Chancellor) on May 23, 2009 at 11:30 UTC

    Yes, of course. Your benchmark is even more appropriate to show the overhead, which consists in creating, populating and destroying a hash (call with hashref) vs. populating a hash already allocated on the subroutine's pad (call with list).

    Might be small, but might sum up. Call it a micro-de-optimization, but I see no value in making perl slower for a questionable gain and a loss of readability.