[Melbourne-pm] returning hashes and arrays, source filters considered harmful?

Toby Corkindale toby.corkindale at strategicdata.com.au
Thu Feb 18 17:01:52 PST 2010


On 19/02/10 11:49, Tulloh, David wrote:
> When in doubt benchmark, it's difficult to guess at the internal
> workings of a interpretted language.  I ran the attached benchmark
> and found returning @foo was faster than \@foo.

I have edited your function to use Benchmark, which is a more reliable 
way of benchmarking these sorts of things.

It's results:
byRef: 11755/s
byValue: 7803/s

Showing that the reference method is quite a bit faster.
(See attached)

> The difference is trivial though and I would suggest using whatever
> format works best for you and then standardising on it.  I personally
> use return @foo because I like passing the output into list functions
> like grep and map (@bar = map {} grep {} my_sub) and it's cleaner
> without the @{} everywhere.

I agree.

I like to pass in and return arrays from things that are functional 
functions.. ie. they take a set of things, and return a set of things, 
without much state affecting them.

For more complex operations I prefer to create blessed objects and 
accessors, which have map/filter/for style operators upon them.


-Toby
-------------- next part --------------
A non-text attachment was scrubbed...
Name: array_return_benchmark2.pl
Type: text/x-perl
Size: 313 bytes
Desc: not available
URL: <http://mail.pm.org/pipermail/melbourne-pm/attachments/20100219/b6589938/attachment.bin>


More information about the Melbourne-pm mailing list