Re: what is encapsulation in an interface ?
Ken Wesson wrote:
I think my for loop is a bit clearer (and probably runs quite a bit
faster) than Tom's code.
Arne Vajh??j wrote:
Both are O(n) so it would be very surprising to see any
measurable difference.
Stefan Ram wrote:
The runtimes of two implementations of the same algorithm
may still differ by a significant factor. (Optimizations in
this regard, therefore, are also known as ??factor optimizations??.
They do not change the O(...) complexity type, but might still matter.)
I know I'm preaching to the choir, but this conversation about performance has
to be read carefully. Stefan, for example, was precise in his statement, "The
runtimes ... might still matter." The dicey part is knowing if they do
matter, and then which solution works better for various metrics of better.
Performance optimization is notoriously difficult to predict. I'm no expert,
but I've participated in both large and small performance investigations and
the pundits absolutely have the right of it. One must measure, and be clear
about specific performance goals under clearly delineated system loads.
A statement like "my for loop ... probably runs quite a bit faster than Tom's
code [that uses standard API calls]" is ill founded on two counts, the
"probably" and the "runs quite a bit faster". It's also meaningless outside a
context of a particular application server profile.
We can impute a desktop profile from the mention of Swing APIs, so OK there.
But even without looking at the specific implementation of the specific API
calls, I can guess that at worst they encapsulate pretty much the same 'for'
loop. For desktop scenarios where relative performance matters, HotSpot would
drown the differences imposed by an extra method call. At best the API uses
what it uses so many places, delegates to native calls that are pretty damn
fast and "probably" will outperform one's own Java code "quite a bit".
Which difference under contemplated use loads might also be erased by HotSpot.
I don't know.
--
Lew
Ceci n'est pas une pipe.