DEV Community

Discussion on: 9 tips to Increase your Java performance β˜•οΈ πŸš€ πŸšΆβ€β™‚οΈ

Collapse
 
mt3o profile image
mt3o

Some of the things are irrelevant because recent JVM can optimize them. I'm taking about StringBuffer and perhaps some stuff involving inlining of your code. However the 1000 repetition limit is not enough to experience that.

Collapse
 
awwsmm profile image
Andrew (he/him)

Especially things like #6. I'm sure the JVM would inline those calculations if the intermediate variables aren't used anywhere else.

Collapse
 
sendilkumarn profile image
Sendil Kumar • Edited

The #6 is just an example.

I completely agree JVM optimizes in a lot of ways.

Thread Thread
 
sendilkumarn profile image
Sendil Kumar • Edited

StringBuffer is way more efficient than normal String concatenation.

Benchmark                     Mode  Cnt      Score     Error  Units
Benchmark.First.stringBuffer  thrpt   25  52791,073 Β± 196,355  ops/s
Benchmark.First.stringConcat  thrpt   25   7355,182 Β±  39,284  ops/s

And this is on JDK 12.

Thread Thread
 
mt3o profile image
mt3o

For some reason your JDK decided out to replace str concat with stringbuilder.
Look here for more information:
dzone.com/articles/jdk-9jep-280-st...