Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Efficient bit-twiddling in Perl.

by salva (Abbot)
on Feb 28, 2013 at 15:17 UTC ( #1021066=note: print w/replies, xml ) Need Help??

in reply to Efficient bit-twiddling in Perl.

Not a big improvement, but you can eliminate the AND operation when calculating $top14.

If you have to do that millions of times, you can try building a table for the combined three 6bit quantities:

my @table; $table[$_] = [..., ..., ...] for 0..0x0003ffff; ... for my $n (...) { my $top = $n >> 18; my ($nxt, $mid, $bot) = @{$table[$n & 0x0003ffff]}; ... }

Replies are listed 'Best First'.
Re^2: Efficient bit-twiddling in Perl.
by BrowserUk (Pope) on Feb 28, 2013 at 19:13 UTC
    you can try building a table for the combined three 6bit quantities:

    The lookup table gains about 20%. Less than I expected, but worth having. Thank you.

    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://1021066]
[stevieb]: finally, my MCP41010 digital potentiometers have arrived! This will be my first crack at writing C code to maniuplate hardware directly by reading the datasheet only (no code reviews before starting)

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2017-01-19 22:04 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (172 votes). Check out past polls.