GitHub user otaviojava opened a pull request:

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

    Optimize string operations

    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 type.
    
    ```java
    @Warmup(iterations = 5, time = 1)
    @Measurement(iterations = 20, time = 1)
    @Fork(3)
    @BenchmarkMode(Mode.Throughput)
    @OutputTimeUnit(TimeUnit.MILLISECONDS)
    @State(Scope.Thread)
    public class StringBenchmark {
    
    
        private static final int COUNT = 300;
        private static final String TEXT = RandomStringUtils.randomAscii(COUNT);
    
        @Benchmark
        public boolean equals() {
            return TEXT.equals("");
        }
    
        @Benchmark
        public boolean isEmpty() {
            return TEXT.isEmpty();
        }
    
    
        @Benchmark
        public int indexOfString() {
            return TEXT.indexOf("a");
        }
    
        @Benchmark
        public int indexOfChar() {
            return TEXT.indexOf('a');
        }
    
    }
    ```
    
    Result:
    
    |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|
    
    
    


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/otaviojava/tomee optmization_string

Alternatively you can review and apply these changes as the patch at:

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

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #261
    
----
commit 5d75e345b90dea135e3d1109bfde1032f091df10
Author: Otavio Santana <otaviopolianasantana@...>
Date:   2018-12-07T19:49:17Z

    updates strings to use isEmpty method

commit fbe2c486d8c9000626126c8dba9ee694e7b04682
Author: Otavio Santana <otaviopolianasantana@...>
Date:   2018-12-07T19:51:01Z

    Uses indexOf with chart instead of String

----


---

Reply via email to