Re: why use pow(x, 2)?
Re: why use pow(x, 2)?
- Subject: Re: why use pow(x, 2)?
- From: Bob Smith <email@hidden>
- Date: Mon, 2 Nov 2009 15:22:36 -0800
On Nov 2, 2009, at 11:38 AM, Luke the Hiesterman wrote:
On Nov 2, 2009, at 11:36 AM, Sherm Pendley wrote:
On Mon, Nov 2, 2009 at 2:25 PM, Ed Wynne <email@hidden> wrote:
That said, the original question is a good one. Using x*x instead of
pow(x,2) would be quite a bit faster
Are you certain of that? With loop unrolling and inlined functions,
it
should result in identical code being produced by the compiler.
so except for clarity reasons, there isn't a
good reason to use pow() in that case.
Clarity should be the default, not the exception. Unless you've
profiled your code and found the use of pow() to be a significant
bottleneck, there's no good reason *not* to use it.
Completely agree. Never assume a performance problem until there is
one.
True, and not true, IMHO. It can be a pitfall to worry about
performance issues too early in a coding project. On the other hand,
by the time you know there is a performance problem it can easily be
too late for low-level code optimization, and you end up with band-aid
solutions like caching that impose unnecessary modality on the UI. So
I think it is still very important for new programmers to be aware of
these issues. Develop good habits for writing efficient code, and you
have a much lower chance of ever having performance problems to
solve. And since compiler optimizations are never certain, it's best
to assume a function call is always more expensive than inline code.
Learn to use macros effectively to enhance clarity and readibility.
All you youngsters who never ran an app on a CPU at less than GHz
speeds, you ought to be forced to write code for an early-80's PC.
Now that was _real_ programming!
Bob
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden