Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

The problem with premature optimization...

by nferraz (Monk)
on Jun 11, 2007 at 11:07 UTC ( [id://620462]=note: print w/replies, xml ) Need Help??


in reply to Premature and micro optimization...

You're talking about a sub which can be executed 300 thousand times per second, which means it will take something like 3 microseconds of computer time each time it is called. If you "optimize" it, it will take 1-2 microseconds; if you do more checking and validation, which actually improves your program, it will take 5-10 microseconds.

Now, take a look on the rest of your program: accessing the database, processing your data, rendering the template probably take a another hundreds or thousands of microseconds!

The fact is that, no matter how much you "optimize" this sub -- you could make it instantaneously-fast, or even remove it, and it wouldn't have a significant impact on the global performance at all.

Moreover, if someone actually considers the idea of removing functionality to improve the local performance, that's the perfect example of premature optimization being the root of all evil.

Replies are listed 'Best First'.
Re: The problem with premature optimization...
by shmem (Chancellor) on Jun 11, 2007 at 12:37 UTC
    No doubt chargill will agree with you that this sort of micro-optimization is just plain silly, since he wrote
    To borrow a phrase from bobf, I "went all perlmonks on him". "Blah blah blah premature optimization blah blah micro optimization blah blah blah." I essentially suggested we throw it on the servers and see if it causes a problem.

    One giant long-running company meeting later, and I'm staring at 20 minutes until it's time to go home for the weekend. Honestly, my curiosity got the better of me and I quickly and quietly setup a little Benchmark.

    - but that's not the point of his post. It is about he being puzzled with why assignment of split results to two my-variables and returning those my-variables could be faster than directly returning the split results.

    Which isn't. :-)

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: The problem with premature optimization...
by chargrill (Parson) on Jun 11, 2007 at 12:20 UTC

    Yes - you're right. I agree, but sometimes I get curious. In fact, my first suggestion was that it would likely make such little difference that no harm would be done by making the change live and then dealing with "performance issues" later, knowing full well that this wouldn't become an issue.


    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
Re: The problem with premature optimization...
by halley (Prior) on Jun 11, 2007 at 14:55 UTC
    The fact is that, no matter how much you "optimize" this sub -- you could make it instantaneously-fast, or even remove it, and it wouldn't have a significant impact on the global performance at all.

    That's a pretty narrow definition of 'global performance' there. Just because it's not the bottleneck in his application doesn't mean you should be happy to burn up CPU cycles endlessly while waiting for the database/network/user/whatever to complete.

    While I agree that premature optimization is a big waste of development time, at runtime some non-bottleneck optimization does add value. That CPU could be used by another process on the same server, or it could run cooler when there's nothing else to do.

    --
    [ e d @ h a l l e y . c c ]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://620462]
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: (5)
As of 2024-03-19 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found