• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StringBuffer performance

 
deepa sundaram
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic