Re: performance improving tactics vs. optimizer.



Roedy Green wrote:
see http://mindprod.com/project/stringbuilderoptimiser.html

from which:
Convert sb.append ( " " ) to sb.append ( ' ' );

This might not be much of an optimization. The String " " is literal, and therefore will be obtained directly from the intern pool. HotSpot will see an indirect reference to the same location in the JVM for the argument of each 'append(" ")'. 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.

Just to invent fictional numbers by way of example, let's say the String benchmark time is two granoseconds ("grano-" being the prefix for whatever is the appropriate granularity of measurement), and the character time is one granosec. One would hope that the optimized String call would come down from 2 granosec to something close to one. Also, if you happen to test on a JVM whose authors have already optimized the String call, you might find that the "before" difference is surprisingly small. Maybe the difference without your optimization is only 1.001 granosec for the String call vs. one for the character case, once HotSpot warms up.

--
Lew
.



Relevant Pages

  • [TOMOYO #15 3/8] Common functions for TOMOYO Linux.
    ... This file contains common functions (e.g. policy I/O, pattern matching). ... Since TOMOYO Linux is a name based access control, ... TOMOYO Linux's string manipulation functions make reviewers feel crazy, ... the Linux kernel accepts all characters but NUL character ...
    (Linux-Kernel)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • Re: RfD: Escaped Strings
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... \b BS (backspace, ASCII 8) ... \ ** escapes to characters much as C does. ...
    (comp.lang.forth)
  • Re: A note on computing thugs and coding bums
    ... code is valid for any character set that is legal in C (which is a ... characters in the required source character set ... A String, in C Sharp or Java, can be redefined. ... allow programmers to handle some other data format, ...
    (comp.programming)