Rolf said:
Victor said:
Christof said:
[..]
Eliminating the function parameter saved 2 CPU cycles in a 30 CPU
cycles buffer allocation routine. Probably not worth to accept poor
code, but but worth to ask.
Yes, if all that your program does is initialising of those objects,
then saving 2 of 30 CPU cycles in the constructor means overall 6%
improvement. Now, consider *the entire* program. How much of your
program's *entire* execution is spent in that constructor? 0.1%?
Or even 0.01%? Now, you've managed to improve *that* by another 6%.
Good. What does it mean to the overall program execution? It got
faster by 0.006% (or by 0.0006%)? Optimize what *really matters*.
If you write a program that does a batch calculation, that argument is
valid. But many programs (like e.g. GUI programs) are event driven.
So, for an event driven program the argument to optimize what *really
matters* is _invalid_; is that what you're saying?
In that case, you often don't care how much percentage of the whole
execution time some specific function takes, but rather how quickly
you react to the event.
I was talking not about the elapsed time (which is of course huge in
GUI-driven programs), but of the CPU time. And if you want to talk
reacting to an event, then 2 CPU cycles won't make a difference, in
most cases. To understand the need to optimize a certain part of the
application, you still *need to time that part*. It does not matter
whether it's 100%, from process startup to closing, or it's a tiny
fraction taken by responding to an event.
Arguing about it won't change the fundamental problem with the OP's
approach - optimize the constructor without even *knowing* how much
it's contributing to the execution time. I think you would agree
that even reacting to an event cannot be a single call to a class
constructor (or a million of single calls to the class constructor).
It's got to be something more. That something often makes a huge
difference.
And if the OP comes back saying that he wanted to optimize a million
calls to the constructor _in a row_ and thus cared about the 6%, I
would immediately ask for the details because initialising 1M objects
with hard-coded values should most likely not be done one by one, but
in a loop, or with a memset, or some such. So, we're back to a few
objects whose initialisation is scattered across tons of other code.
Need I continue?
V