Optimize string operations

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Optimize string operations

Otávio Gonçalves de Santana
This PR has the goal to optimize String operations in the module container.

   - The first operation is instead of using the method isEmpty instead of
   use string.equals("")
   - The second operation changes a String with one characater to a char

@Warmup(iterations = 5, time = 1)@Measurement(iterations = 20, time =
class StringBenchmark {

    private static final int COUNT = 300;
    private static final String TEXT = RandomStringUtils.randomAscii(COUNT);

    public boolean equals() {
        return TEXT.equals("");

    public boolean isEmpty() {
        return TEXT.isEmpty();

    public int indexOfString() {
        return TEXT.indexOf("a");

    public int indexOfChar() {
        return TEXT.indexOf('a');


Benchmark Mode Cnt Score unit
equals thrpt 60 333414,466 ops/ms
isEmpty thrpt 60 380694,204 (around 20%faster) ops/ms
indexOfString thrpt 60 78423,569 ops/ms
indexOfChar thrpt 60 105625,484(around 20%faster) ops/ms

Ref: https://github.com/apache/tomee/pull/261