Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: RFC extending to facilitate CODEHASHREF

by Eily (Curate)
on Nov 26, 2013 at 00:27 UTC ( #1064343=note: print w/ replies, xml ) Need Help??

in reply to RFC extending to facilitate CODEHASHREF

To get a lighter syntax you can already do something like :

my @arr_1 = map {rand 1e6} 8000; my @arr_2 = map {rand 1e6} 6000; my $cmp = { hash_values_diff => sub { my %diff3; @diff3{@arr_1} = @arr_1; delete @diff3{@arr_2}; values %diff3 ; }, using_vec => sub { my $vec = ''; vec( $vec, $_, 1 ) = 1 for @arr_2; grep !vec( $vec, $_, 1 ), @arr_1; }, hash_grep => sub { my %arr_2_hash; undef @arr_2_hash{@arr_2}; grep !exists $arr_2_hash{$_}, @arr_1; } }; cmpthese(-3, $cmp);
I do like the package approach more though, because there's no reference to a hash of refences to subs, which probably is quite unsettling for beginners. And even if they don't understand how it works, it's surely better if they at least understand the syntax to use it, instead of just copying an exemple with even weirder concepts than those they already have trouble understanding.

If you go for the package solution, you might as well have it use parent YourBenchmark, so that you can call CMP->benchmark(-5);. And you may want to add filtering of some sort, because one might want to call a function imported from another package inside of the functions that should be benchmarked. I'm sure someone could have come up with a function using something out of List::AllUtils for the exemple you gave. Edit: and you already said that with using the attributes as the tool for selecting the benchmarked subs, my bad.

Comment on Re: RFC extending to facilitate CODEHASHREF
Select or Download Code
Replies are listed 'Best First'.
Re^2: RFC extending to facilitate CODEHASHREF
by LanX (Chancellor) on Nov 26, 2013 at 14:33 UTC

    Thanks for the input, pointing me to new use cases ! :)

    I'm pretty sure it's possible to exclude imported subs.

    And passing optional filter-conditions (like regex) operating on sub-names are a good idea.

    Combined with optional attributes all cases should be covered.

    Will show a proof of concept soon. : )

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2015-11-27 22:31 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (734 votes), past polls