Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^10: Smartmatch alternatives

by LanX (Canon)
on Dec 18, 2013 at 08:15 UTC ( #1067609=note: print w/ replies, xml ) Need Help??


in reply to Re^9: Smartmatch alternatives
in thread Smartmatch alternatives

*COMPLETELY UPDATED, FORGET WHAT I WROTE BEFORE IN THIS POST*

Sorry using string benchmarks didn't combine well with lexical globals in my last benchmark.

Your benchmark with ano-subs shows LMU being 3 times as fast for arrays of length 1000.

use strict; use warnings; use Benchmark qw(cmpthese); use Data::Dump qw/pp/; #use List::Util 1.35 (); BEGIN { *any_lu = *List::Util::any }; use List::MoreUtils (); BEGIN { *any_lmu = *List::MoreUtils::any }; sub any_pp (&@) { my $code = shift; map {&$code and return 1} @_ ; () +} my (@LIST,$TARGET); our (@LIST2,$TARGET2); { no warnings 'once'; @LIST2 = @LIST = (0..1000); $TARGET2 = $TARGET = $LIST[@LIST/2]; } local $,="\t"; my $suite= { any_lmu => sub { any_lmu { $_ eq $TARGET } @LIST }, any_pp => sub { any_pp { $_ eq $TARGET } @LIST }, }; pp $suite; cmpthese(-1,$suite); __END__ { any_lmu => sub { "???" }, any_pp => sub { "???" } } Rate any_pp any_lmu any_pp 1027/s -- -66% any_lmu 3027/s 195% --


Comment on Re^10: Smartmatch alternatives
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-09-20 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (157 votes), past polls