Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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

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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://92856]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2018-06-24 10:20 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.