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

Re: Optimizations and Efficiency

by srawls (Friar)
on Jun 30, 2001 at 05:14 UTC ( #92856=note: print w/ replies, xml ) Need Help??


in reply to Optimizations and Efficiency

$x = $y * 16; $x = $y << 4; #Much faster

First I must note that I love these types of micro-optimizations. Durring the winter I work on a robotics competition where we code in pBasic, and we have to constantly worry about effiency. That said:

There are multiple layers of abstraction between the perl code you write and the machine code produced. When we use a high level language (like perl), we should write what comes natural ($x = $y * 16;), and trust that the interpreter will turn it into the most efficient machine representation. Also, when someone comes along and has to maintain the code, an asembly programmer may very easily understand your optimizations, but odds are a typical perl programmer may not.

The 15 year old, freshman programmer,
Stephen Rawls


Comment on Re: Optimizations and Efficiency
Select or Download Code
Re: Re: Optimizations and Efficiency
by BMaximus (Chaplain) on Jul 01, 2001 at 00:13 UTC
    $x = $y * 16;
    Any good compiler would optimise this for you into this
    $x = $y << 4;
    C and C++ compilers do it automaticaly in the preprocessor. I don't see why Perl wouldn't do it either unless that it was seen that it wasn't needed or that it hasn't been put in yet.

    BMaximus

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-08-02 09:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (55 votes), past polls