Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Optimizations and Efficiency

by srawls (Friar)
on Jun 30, 2001 at 05:14 UTC ( [id://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

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://92856]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-29 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found