Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Efficient bit-twiddling in Perl.

by kennethk (Monsignor)
on Feb 28, 2013 at 19:39 UTC ( #1021102=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Efficient bit-twiddling in Perl.
in thread Efficient bit-twiddling in Perl.

I'll qualify this result to say salva's result doesn't necessarily buy you anything if you are only doing this millions of times. On my machine, I get the timings

Generation took: 0.218580069542 seconds Shift&and took: 0.000000471000 seconds Lookup took: 0.000000395095 seconds
Where generation is calculated with
my $start = time; for (1..100) { my @lookup; $#lookup = 0x3ffff; $lookup[ $_ ] = [ ( $_ & 0x3f000 ) >> 12, ( $_ & 0xfc0 ) >> 6, $_ & 0x +3f ] for 0 .. 0x3ffff; } printf "Generation took: %.12f seconds\n", ( time() - $start )/100;
I ran the transforms for 10^7 iterations, though frankly all metrics were still a little volatile for my taste. This puts breakeven at 2.9 million iterations and 5% speed up at 4.2 million. YMMV.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re^3: Efficient bit-twiddling in Perl.
Select or Download Code
Re^4: Efficient bit-twiddling in Perl.
by BrowserUk (Pope) on Feb 28, 2013 at 19:58 UTC

    The lookup table generation is 2/10th second, 1-off cost at startup.

    Completely insignificant to the cost of the inner loop lookup code that could theoretically be executed 4 billion times. (Once for each 32-bit number.) More typical is mid 100s to low 1000s of millions of times.

    A small saving overall, but only one part of the inner loop code I am optimising. Already down from a couple of weeks to ~4 days.


    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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2014-09-18 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (108 votes), past polls