Wednesday, March 5, 2014

Specifying the size for StringBuilder (jmh)

Several years ago I started doing some microbenchmarks. I don't think that I really progressed since than, but at least some errors became obvious. So I decided to take one of my old benchmarks and reimplement it using the JVM library. Here are the results that I got:

Benchmark                                    Mode   Samples         Mean   Mean error    Units
c.s.m.j.StringBuilderSize.expandingSize      avgt        15     7566.477      374.611    ns/op
c.s.m.j.StringBuilderSize.predefinedSize     avgt        15     5640.386      133.672    ns/op

And here is the code for it. (I have also posted some other jmh-based benchmarks in that repo).