Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-523

StrBuilder is slow

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4
    • 2.5
    • lang.text.*
    • None

    Description

      I need a faster StringBuffer for java 1.4 branch.

      So I tested StrBuffer. The result is not sufficient as it is 500 times slower than StringBuffer. The problem is that currently the StrBuilder increases the buffer size by the length of the string that thought to be appended.

      Changing this strategy to provide the double of the needed buffer size brings the performance near to the StringBuilder.

      Here the times (the average of four runs in ms) for the Testcase attached. Where MyStrBuilder is the pathed version of StrBuilder

      startStringBuffer: 105.25
      startStrBuilder: 5863.75
      startStringBuilder: 55
      startMyStringBuilder: 54

      Attachments

        1. patch.txt
          0.5 kB
          Stefan Zeller
        2. Test.java
          3 kB
          Stefan Zeller

        Activity

          People

            Unassigned Unassigned
            stzel Stefan Zeller
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: