Java Magazine, May/June 2018
ORACLE COM JAVAMAGAZINE MAY JUNE 2018 76 inside the jvm @ Benchmark public String concatWithStringBuffer final StringBuffer buffer new StringBuffer for String piece pieces buffer append piece return buffer toString @ Benchmark public String concatWithStringBuilder StringBuilder builder new StringBuilder for String piece pieces builder append piece return builder toString Lock elision has been a very successful optimization and is enabled by default as of Java 8 but it can be disabled using the XX DoEscapeAnalysis VM switch so that you can see the impact of the optimization With escape analysis enabled the default the performance of StringBuffer and StringBuilder is almost identical The results are reported in operations per second A higher score indicates better performance concatWithStringBuffer 16280252994 17K ops s concatWithStringBuilder 16479504748 34K ops s
You must have JavaScript enabled to view digital editions.