[jira] [Created] (LANG-1358) Improve StringUtils#replace throughput

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

[jira] [Created] (LANG-1358) Improve StringUtils#replace throughput

JIRA jira@apache.org
Pascal Schumacher created LANG-1358:
---------------------------------------

             Summary: Improve StringUtils#replace throughput
                 Key: LANG-1358
                 URL: https://issues.apache.org/jira/browse/LANG-1358
             Project: Commons Lang
          Issue Type: Improvement
    Affects Versions: 3.6
            Reporter: Pascal Schumacher
            Priority: Minor


{quote}
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/StringBuilder.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-vs-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
{quote}

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



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)