Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: An array of boolean values in a bitfield

by bennymack (Pilgrim)
on Dec 05, 2008 at 14:22 UTC ( [id://728294]=note: print w/replies, xml ) Need Help??


in reply to Re: An array of boolean values in a bitfield
in thread An array of boolean values in a bitfield

I'm not a PDL expert by any means but I did up a simple benchmark for it. It only seems to be faster for larger vectors. I didn't check them memory usage but I assume it's higher. I feel that the real win using PDL is the auto-threading and the cleanliness of the code that it provides.

use PDL; foreach my $t ( @tests ) { my $bits = mkbits( @{ $t } ); my $pdl = pdl( map { vec( $bits, $_, 1 ) } 0 .. length( $bits ) * + 8 ); cmpthese( -1, { 'vec' => sub { vec_count( $bits ) }, 're' => sub { re_count( $bits ) }, 'chop' => sub { chop_count( $bits ) }, 'loop' => sub { loop_count( $bits ) }, 'pdl' => sub { pdl_count_1( $pdl ) }, }); } sub pdl_count_1 { my ( $pdl ) = @_; # return $pdl->which->getdim( 0 ); return $pdl->which->nelem; } __END__ 8, 1 Rate pdl vec re loop chop pdl 102399/s -- -75% -82% -85% -90% vec 413537/s 304% -- -29% -39% -59% re 584645/s 471% 41% -- -14% -42% loop 681314/s 565% 65% 17% -- -32% chop 1006035/s 882% 143% 72% 48% -- 8, 8 Rate pdl vec re loop chop pdl 101433/s -- -76% -83% -86% -90% vec 417552/s 312% -- -29% -41% -58% re 584645/s 476% 40% -- -17% -41% loop 703248/s 593% 68% 20% -- -29% chop 988689/s 875% 137% 69% 41% -- 1000, 1 Rate vec loop chop pdl re vec 8499/s -- -80% -82% -88% -97% loop 41533/s 389% -- -12% -40% -86% chop 47287/s 456% 14% -- -31% -84% pdl 68922/s 711% 66% 46% -- -76% re 290443/s 3317% 599% 514% 321% -- 1000, 10 Rate vec loop chop pdl re vec 8614/s -- -79% -81% -87% -93% loop 40785/s 373% -- -12% -40% -67% chop 46419/s 439% 14% -- -31% -62% pdl 67622/s 685% 66% 46% -- -45% re 123675/s 1336% 203% 166% 83% -- 1000, 100 Rate vec re loop chop pdl vec 8532/s -- -71% -79% -81% -86% re 29538/s 246% -- -27% -35% -50% loop 40193/s 371% 36% -- -12% -33% chop 45510/s 433% 54% 13% -- -24% pdl 59650/s 599% 102% 48% 31% -- 1000, 500 Rate vec re loop pdl chop vec 8533/s -- -50% -78% -80% -81% re 17148/s 101% -- -57% -60% -61% loop 39456/s 362% 130% -- -8% -11% pdl 42708/s 400% 149% 8% -- -3% chop 44246/s 419% 158% 12% 4% -- 1000, 900 Rate vec re loop pdl chop vec 9050/s -- -46% -77% -78% -80% re 16747/s 85% -- -58% -60% -63% loop 40193/s 344% 140% -- -3% -11% pdl 41533/s 359% 148% 3% -- -8% chop 45081/s 398% 169% 12% 9% -- 1000000, 1 Rate vec loop chop pdl re vec 8.57/s -- -81% -84% -96% -99% loop 44.1/s 415% -- -18% -77% -93% chop 54.1/s 531% 22% -- -72% -92% pdl 193/s 2148% 336% 256% -- -71% re 667/s 7681% 1411% 1134% 246% -- 1000000, 100 Rate vec loop chop pdl re vec 8.65/s -- -80% -83% -96% -99% loop 44.2/s 411% -- -12% -77% -93% chop 50.5/s 483% 14% -- -74% -92% pdl 194/s 2147% 340% 285% -- -70% re 643/s 7327% 1353% 1174% 231% -- 1000000, 100000 Rate vec re loop chop pdl vec 8.57/s -- -72% -80% -82% -94% re 30.5/s 256% -- -29% -35% -79% loop 42.7/s 398% 40% -- -9% -71% chop 47.1/s 450% 55% 10% -- -68% pdl 148/s 1622% 384% 245% 213% -- 1000000, 500000 Rate vec re loop chop pdl vec 8.65/s -- -51% -80% -82% -88% re 17.6/s 103% -- -58% -63% -75% loop 42.3/s 389% 140% -- -11% -40% chop 47.3/s 446% 169% 12% -- -33% pdl 70.4/s 713% 300% 66% 49% -- 1000000, 900000 Rate vec re loop chop pdl vec 8.65/s -- -50% -80% -82% -87% re 17.4/s 101% -- -59% -63% -74% loop 43.0/s 397% 147% -- -10% -35% chop 47.7/s 451% 174% 11% -- -28% pdl 66.0/s 663% 279% 54% 38% --

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-03-29 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found