You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by slandelle <gi...@git.apache.org> on 2017/10/12 08:42:44 UTC

[GitHub] commons-lang pull request #300: Improve StringUtils#replace throughput

GitHub user slandelle opened a pull request:

    https://github.com/apache/commons-lang/pull/300

    Improve StringUtils#replace throughput

    Motivation:
    
    `StringUtils#replace` uses `substring` to append a String region into a
    StringBuilder. This causes useless copies, as `StringBuilder#append`
    can take start and end indexes.
    
    Modification:
    
    Use proper `StringBuilder#append`
    [overload](https://docs.oracle.com/javase/8/docs/api/java/lang/StringBui
    lder.html#append-java.lang.CharSequence-int-int-).
    
    Result:
    
    Based on benchmark from [JOOQ’s
    post](https://blog.jooq.org/2017/10/11/benchmarking-jdk-string-replace-v
    s-apache-commons-stringutils-replace):
    
    ```
    Benchmark Mode Cnt Score Error Units
    StringReplaceBenchmark.testFastStringReplaceLongStringOneMatch thrpt 21
    7546534,219 ± 145523,962 ops/s
    StringReplaceBenchmark.testStringUtilsReplaceLongStringOneMatch thrpt
    21 7353512,552 ± 124498,228 ops/s
    
    StringReplaceBenchmark.testFastStringReplaceLongStringSeveralMatches
    thrpt 21 5077255,810 ± 62358,937 ops/s
    StringReplaceBenchmark.testStringUtilsReplaceLongStringSeveralMatches
    thrpt 21 4108357,612 ± 92909,038 ops/s
    
    StringReplaceBenchmark.testFastStringReplaceShortStringOneMatch thrpt
    21 15911221,949 ± 541064,693 ops/s
    StringReplaceBenchmark.testStringUtilsReplaceShortStringOneMatch thrpt
    21 10677897,475 ± 491091,973 ops/s
    
    StringReplaceBenchmark.testFastStringReplaceShortStringSeveralMatches
    thrpt 21 9271742,251 ± 220150,121 ops/s
    StringReplaceBenchmark.testStringUtilsReplaceShortStringSeveralMatches
    thrpt 21 6158829,188 ± 99637,607 ops/s
    ```

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

    $ git pull https://github.com/slandelle/commons-lang master

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

    https://github.com/apache/commons-lang/pull/300.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 #300
    
----
commit 7280a495492c87680c6a13041bd3948f174a25a0
Author: Stephane Landelle <sl...@gatling.io>
Date:   2017-10-12T08:41:53Z

    Improve StringUtils#replace throughput
    
    Motivation:
    
    `StringUtils#replace` uses `substring` to append a String region into a
    StringBuilder. This causes useless copies, as `StringBuilder#append`
    can take start and end indexes.
    
    Modification:
    
    Use proper `StringBuilder#append`
    [overload](https://docs.oracle.com/javase/8/docs/api/java/lang/StringBui
    lder.html#append-java.lang.CharSequence-int-int-).
    
    Result:
    
    Based on benchmark from [JOOQ’s
    post](https://blog.jooq.org/2017/10/11/benchmarking-jdk-string-replace-v
    s-apache-commons-stringutils-replace):
    
    ```
    Benchmark Mode Cnt Score Error Units
    StringReplaceBenchmark.testFastStringReplaceLongStringOneMatch thrpt 21
    7546534,219 ± 145523,962 ops/s
    StringReplaceBenchmark.testStringUtilsReplaceLongStringOneMatch thrpt
    21 7353512,552 ± 124498,228 ops/s
    
    StringReplaceBenchmark.testFastStringReplaceLongStringSeveralMatches
    thrpt 21 5077255,810 ± 62358,937 ops/s
    StringReplaceBenchmark.testStringUtilsReplaceLongStringSeveralMatches
    thrpt 21 4108357,612 ± 92909,038 ops/s
    
    StringReplaceBenchmark.testFastStringReplaceShortStringOneMatch thrpt
    21 15911221,949 ± 541064,693 ops/s
    StringReplaceBenchmark.testStringUtilsReplaceShortStringOneMatch thrpt
    21 10677897,475 ± 491091,973 ops/s
    
    StringReplaceBenchmark.testFastStringReplaceShortStringSeveralMatches
    thrpt 21 9271742,251 ± 220150,121 ops/s
    StringReplaceBenchmark.testStringUtilsReplaceShortStringSeveralMatches
    thrpt 21 6158829,188 ± 99637,607 ops/s
    ```

----


---

[GitHub] commons-lang pull request #300: Improve StringUtils#replace throughput

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/commons-lang/pull/300


---

[GitHub] commons-lang issue #300: Improve StringUtils#replace throughput

Posted by slandelle <gi...@git.apache.org>.
Github user slandelle commented on the issue:

    https://github.com/apache/commons-lang/pull/300
  
    Note: `substring` overhead happens since Java 7 (since it actually does a copy).


---

[GitHub] commons-lang issue #300: Improve StringUtils#replace throughput

Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:

    https://github.com/apache/commons-lang/pull/300
  
    
    [![Coverage Status](https://coveralls.io/builds/13683982/badge)](https://coveralls.io/builds/13683982)
    
    Coverage remained the same at 95.199% when pulling **7280a495492c87680c6a13041bd3948f174a25a0 on slandelle:master** into **274dbfe81f5f43a47639623c62fc998b5eccd5f0 on apache:master**.



---

[GitHub] commons-lang issue #300: Improve StringUtils#replace throughput

Posted by PascalSchumacher <gi...@git.apache.org>.
Github user PascalSchumacher commented on the issue:

    https://github.com/apache/commons-lang/pull/300
  
    Thanks! 👍 


---