Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: RFC extending Benchmark.pm to facilitate CODEHASHREF

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


in reply to RFC extending Benchmark.pm 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.

Replies are listed 'Best First'.
Re^2: RFC extending Benchmark.pm to facilitate CODEHASHREF
by LanX (Saint) on Nov 26, 2013 at 14:33 UTC
    Hi

    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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-03-19 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found