wood burning stoves 2.0*
The moose likes Performance and the fly likes StringBuffer performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "StringBuffer performance " Watch "StringBuffer performance " New topic
Author

StringBuffer performance

deepa sundaram
Greenhorn

Joined: Feb 11, 2005
Posts: 11

In the below code, I wanted to check the time taken by StringBuffer to do a concatination, by passing the string in two different ways. I got 750ms and 450ms respectively. What is wrong in passing the string in my second approach?Would be nice if anyone explains me theory behind this. Thanks a lot.


Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Nothing.

What result did you expect? You do the costly string concatenation in line 16 before handing over the concatenated string to the StringBuffer. So no surprise it is slower.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: StringBuffer performance
 
Similar Threads
Bug in code, need an outside perspective - cannot figure it out.
Needs Explanation
thread priority
Difference between '+' and concat in string
Multi Threading