Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Most Significant Set Bit

by hippo (Archbishop)
on Mar 15, 2024 at 23:07 UTC ( [id://11158299]=note: print w/replies, xml ) Need Help??


in reply to Re: Most Significant Set Bit
in thread Most Significant Set Bit

Unfortunately the log function isn't inexpensive

True, but you can halve the expense for large numbers of evaluations by storing log(2), which is just a constant.


🦛

Replies are listed 'Best First'.
Re^3: Most Significant Set Bit
by Danny (Chaplain) on Mar 15, 2024 at 23:20 UTC
    Strangely using a stored $log2 = log(2) in the above test did not improve the log function speed. It was actually slightly slower.

    EDIT: similar also with use constant log2 => log(2)

    EDIT2: The interpreter must compile such constant expressions into a constant before running.

      The interpreter must compile such constant expressions into a constant before running.

      Yes

      $ perl -MO=Concise,-exec -e'my $x = log(2);' 1 <0> enter v 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> const[NV 0.693147180559945] s/FOLD 4 <1> padsv_store[$x:1,2] vKS/LVINTRO 5 <@> leave[1 ref] vKP/REFC -e syntax OK

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2026-01-13 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (118 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.