Christopher James Huff wrote:
>> Sometimes there is also an additional temporary variable created.
>
> You are micro-optimizing...though I am sometimes guilty of that too.
> A good compiler can often figure out the most efficient way to compile
> the code.
Well, that's probably quite true.. I am "unoptimizing" by and by things for
sake of a better abstraction. And I have already add the + operator to the
colour classes when I had used a nasty integration formula for the media
stuff.
>
>> will have to be tranlated by the compiler to
>> tmp = c;
>> tmp += b;
>> a += tmp;
>> as it cannot assume that (a+b)+c is the same as a+(b+c). On the other
>> hand
>> a.add(b); a.add(c);
>> does not need a temporary variable.
>
> a += b; a += c;
> or:
> (a += b) += c;
>
> No temporaries.
But you probably wouldn't write it like this when you had the + available.
> The version using operator overloading is much easier to read, and the
> compiler could probably optimize away any significant differences.
>
I still think the programmer is more forced to think about the best
operation sequence when one has to apply them one by one and cannot just
put lengths of forumlas there.
- Micha
--
objects.povworld.org - The POV-Ray Objects Collection
book.povworld.org - The POV-Ray Book Project
Post a reply to this message
|