Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is StringBuffer.append("c1").append("c2") faster ? than spli

Status
Not open for further replies.

remyvrs

Programmer
Jul 12, 2005
66
0
0
RO
I am in kind of a dilema:
is there a reason to think that this section:

StringBuffer sb = new StringBuffer(100);
sb.append("abc").append("def").append("ghi");


works faster than this one:

StringBuffer sb = new StringBuffer(100);
sb.append("abc");
sb.append("def");
sb.append("ghi");


It's nice to be important but it's more important to be nice.
Thanks for your attitude!
 
There's a medium term for everything.

I don't think you should write your code only to make it run. Some good coding practices are esay to carry out and cover a big part of the optimization at code level. String concatenations is one of that.

In the other hand, the big optimization problems come from the design part, not the coding part. In this case, I'd say that a JSP that involves all that data handling could have a little re-design.

And at code level, optimization can make the code more difficult to read and maintain, and that ends on a waste of time.

So analyze your requirements and find your best way to go, that mat be differente from other people's needs.

Cheers,
Dian
 
I have been 4 days offline and see most questions asked.

I just like to mention two things: How shall we answer an optimization-question, when the question isn't accurate, showing 3 stringliterals, while in real life they are dynamic?

And if the strings are coming from the database, perhaps it would be more performant, to let the database do the catenation (which we may not answer without knowing more details).

Of course a well informed programmer will use StringBuffer.append without using a profiler, but only, when he knows, that performance might be an issue, that the code might be run thousend of times inside a loop.

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top