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

Re: Efficient bit-twiddling in Perl.

by dave_the_m (Prior)
on Feb 28, 2013 at 15:51 UTC ( #1021069=note: print w/replies, xml ) Need Help??

in reply to Efficient bit-twiddling in Perl.

Note that the code you've got is already fairly efficient. Consider the following:
my $n = 0x80061861; for (1..10_000_000) { my $top14 = ( $n & 0xfffc0000 ) >> 18; my $nxt6 = ( $n & 0x0003f000 ) >> 12; my $mid6 = ( $n & 0x00000fc0 ) >> 6; my $bot6 = ( $n & 0x0000003f ); # or replace the four lines above with: #my ($top14, $nxt6, $mid6, $bot6) = (1,1,1,1); }
Running as-is on my system takes 3.1s; using just the last line (which represents a baseline of creating, setting and freeing those four lexical vars), takes 1.9s. So any savings you make are likely to be less than that.


Replies are listed 'Best First'.
Re^2: Efficient bit-twiddling in Perl.
by BrowserUk (Pope) on Feb 28, 2013 at 17:59 UTC

    Se Re^2: Efficient bit-twiddling in Perl. for my starting position.

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1021069]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2018-06-20 21:26 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.