Re: performance improving tactics vs. optimizer.
On Sun, 13 Apr 2008 08:48:17 -0400, Lew <lew@lewscanon.com> wrote,
quoted or indirectly quoted someone who said :
That's only one hop longer than a direct load of the
character. Part of the student project (excellent service to the community to
post those projects, btw) should be to benchmark the difference between the
String- and character-argument calls before implementing the optimization, and
to compare any change in the String-argument call times to that difference as
well.
When you are writing general purpose optimisers you go for broke. You
shave every nanosecond you can. It may matter to someone, even if
just an artificial benchmark against the competition.
For a given application, of course, you measure and don't bother with
negligible optimisations.
To an assembler programmer such as myself append(' ') is obviously
vastly faster than append (" "). Because it is a trivial
optimisation, so you might as well do it.
append( ' ' )
might be optimised roughly like this:
if ( ++bufflen >= bufflimt ) { handleOverflow() };
buff[ bufflen ] = ' ';
append( " ")
will be roughly implemented like this:
int end = bufflen + literalxxx.length();
if (end >= bufflimt ) { handleOverflow() };
for ( int i = 0; i< literalxxx.length(); i++ )
{
buff[ bufflen + i ] = literalxxx[ i ];
}
bufflen = end;
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com