Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Efficient selection mechanism?

by oiskuu (Pilgrim)
on Jan 14, 2014 at 23:01 UTC ( #1070624=note: print w/ replies, xml ) Need Help??


in reply to Efficient selection mechanism?

Here's a small bench to highlight the speed difference in some of the chosen strategies.

#! /usr/bin/perl -wl use Benchmark 'cmpthese'; my (@v, @b); @v[0 .. 19] = 'a' .. 'z'; for (1..1e6) { my %r; undef $r{$v[rand @v]} until keys %r == 4; push @b, join '', keys %r; } my @AoA = map [map ord()-97, split //,$_], @b; my @vectors; for my $t (@v) { push @vectors, pack "b*", pack "c*", map !!/$t/, @b; } my $AoA = pack 'C*', map @$_, @AoA; cmpthese -5, { bitmap => sub { my $res = ''; $res |= $vectors[$_] for @{$AoA[0]}; int(@AoA) - unpack "%32b*", $res; }, regex1 => sub { my $omit = $AoA[0]; my $pat = '[^'.( join '', map quotemeta, pack 'C*', @$omit ).' +]{4}'; my $re = qr/\G(?:.{4})*?($pat)/s; int(() = $AoA =~ /$re/g); }, regex2 => sub { my $pat = qr/[$b[0]]/; my $cnt = 0; $cnt += !/$pat/ for @b; $cnt; }, };


Comment on Re: Efficient selection mechanism?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2014-08-31 06:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls