Link Details

Link 284519 thumbnail
User 410289 avatar

By CodeJustin
via venishjoe.net
Published: Nov 09 2009 / 09:45

The quick and dirty way to concatenate strings in Java is to use the concatenation operator (+). This will yield a reasonable performance if you need to combine two or three strings (fixed-size). But if you want to concatenate n strings in a loop, the performance degrades in multiples of n. Given that String is immutable, for large number of string concatenation operations, using (+) will give us a worst performance. But how bad ? How StringBuffer, StringBuilder or String.concat() performs if we put them on a performance test ?. This article will try to answer those questions. We will be using Perf4J to calculate the performance, since this library will give us aggregated performance statistics like mean, minimum, maximum, standard deviation over a set time span. In the code, we will concatenate a string (*) repeatedly 50,000 times and this iteration will be performed 21 times so that we can get a good standard deviation. The following methods will be used to concatenate strings.
  • 10
  • 11
  • 4419
  • 4

Comments

Add your comment
User 61474 avatar

William Louth replied ago:

0 votes Vote down Vote up Reply

No point to article other than

- "how not to write a micro-benchmark"
- "how not to measure"
- "how to measure (wrongly) an irrelevant observation"
....

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Reactive Programming with Akka
Written by: Ryan Knight
Featured Refcardz: Top Refcardz:
  1. Design Patterns
  2. OO JS
  3. Cont. Delivery
  4. Java Performance
  5. HTML5 Mobile
  1. Java Performance
  2. Node.js
  3. Debugging JavaScript
  4. Java
  5. Java Concurrency