On 6/14/2012 7:36 PM, Ade Lee wrote:
> Every time you do a "+" operation on Strings, the JVM
will create a
> StringBuilder, append the Strings, then generate a new String that
> contains the concatenated text. So instead of this:
>
> splitTimes.append(
> "," + Long.toString(deltaTime) + "," +
Long.toString(crlTime)
> + "," + Long.toString(totalTime) + ")");
>
> you can reuse the same StringBuilder object like this:
>
>
splitTimes.append(",").append(deltaTime).append(",").append(crlTime)
> .append(",").append(totalTime).append(")");
>
While I appreciate that the above formulation is more efficient, there
is a drawback in terms of readability. This following formulation may
be a little less efficient but is much more readable:
splitTimes.append("," + deltaTime + "," + crlTime + "," +
totalTime + ")");
I suggest that we not sacrifice readability for efficiency until we have
profiling data in hand. I suspect that this little inefficiency will be
the very least of our performance issues.
Agreed. For better readability we can use this:
splitTimes.append(
String.format(",%d,%d,%d)", deltaTime, crlTime, totalTime));
--
Endi S. Dewata