Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^3: How to make references more like aliases?

by Prior Nacre V (Hermit)
on Sep 29, 2004 at 05:57 UTC ( [id://394868]=note: print w/replies, xml ) Need Help??

in reply to Re^2: How to make references more like aliases?
in thread How to make references more like aliases?

Benchmarking disagrees with you.

The closure is generated only once - my code does more here:

by_groups_of( 3, \@array ); by_groups_of( 3, [ \(@array) ] );

The closure is called multiple times - your code does more here:

return sub { \@_ }->( @$list[ $start .. $stop ] ); return [ @{$ra_list}[$start .. $stop] ];

I benchmarked on a P3/Win98 system using both Cygwin/Perl5.6 and Msys/Perl5.8. I got comparable results for both versions (no discernible speed differences). These results were repeated when volume testing with array sizes between 100,000 and 500,000.

At the end of the day, either will do nicely :-)



Replies are listed 'Best First'.
Re^4: How to make references more like aliases?
by Limbic~Region (Chancellor) on Sep 29, 2004 at 13:29 UTC
    Prior Nacre V,
    Benchmarking disagrees with you.

    Then you misunderstood what I said. I made no claim my code was faster, only that your statement (I generally don't like passing whole arrays), seemed odd given what you were doing is more work than passing a whole array.

    Now my goal was being user-friendly, not being fast which is why I preferred $group->[1] over ${ $group->[1] }. But since you did bring up speed, my rudimentary tests show my code as being much faster. Perhaps you should try the following:

    Cheers - L~R

      This was intended to be friendly, helpful and non-competitive.

      Perhaps you could've replied in a similar vein along these lines:

      Thanks for taking the extra time to compare benchmark results. However, further testing on the intended (platform/OS/Perl version) indicates that my version will run faster and therefore I will be going with that solution.

      Instead of:

      • Using an unsubstantiated claim about what I understand. Are you psychic?
      • Including pointless rhetoric. Neither you nor I claimed your (or my) code was faster. Perhaps take a moment to consider why you added this.
      • Taking my statements out of context.
        • Yet again you have focussed on passing array vs. arrayref while ignoring what is happening in the closure.
        • Claiming I was talking about speed when I was, in fact, talking about speed differences (the former is absolute, the latter is relative).

      Finally, I very much doubt that anyone able to understand the closure generation code will have the slightest problem dereferencing a scalarref. As such, I believe your initial target for improving user-friendliness should be the closure.



Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://394868]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-05-19 06:05 GMT
Find Nodes?
    Voting Booth?

    No recent polls found