Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: RFC extending Benchmark.pm to facilitate CODEHASHREF

by Eily (Deacon)
on Nov 26, 2013 at 00:27 UTC ( #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.


Comment on Re: RFC extending Benchmark.pm to facilitate CODEHASHREF
Select or Download Code
Re^2: RFC extending Benchmark.pm to facilitate CODEHASHREF
by LanX (Canon) 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
Node Status?
node history
Node Type: note [id://1064343]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-12-23 02:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (133 votes), past polls