harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexey Varlamov (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-589) [classlib][luni] java.lang.StringBuilder performs very slowly
Date Tue, 13 Jun 2006 12:13:30 GMT
    [ http://issues.apache.org/jira/browse/HARMONY-589?page=comments#action_12416001 ] 

Alexey Varlamov commented on HARMONY-589:
-----------------------------------------

Sorry, the previous comment should read as:

Attached are 2 files:
1) j.lAbstractStringBuilder is package-private class providing shared functionality for j.l.StringBuilder
& j.l.StringBuffer. 
2) SB.diff contains changes needed to move  j.l.StringBuilder & j.l.StringBuffer to this
common base class.

Now performance results are:
----------------------------------
JIT mode:
append(String) test, ms
        StringBuffer : 30
        StringBuilder : 10
constructor(String) test, ms
        StringBuilder : 20
        StringBuffer : 20
----------------------------------
interpreter mode:
append(String) test, ms
        StringBuffer : 150
        StringBuilder : 131
constructor(String) test, ms
        StringBuilder : 250
        StringBuffer : 250

The suggested fix also eliminates code duplication between j.l.StringBuilder & j.l.StringBuffer,
and absolutely syncs their behavoir up to the finest details.

> [classlib][luni] java.lang.StringBuilder performs very slowly
> -------------------------------------------------------------
>
>          Key: HARMONY-589
>          URL: http://issues.apache.org/jira/browse/HARMONY-589
>      Project: Harmony
>         Type: Improvement

>   Components: Classlib
>     Reporter: Alexey Varlamov
>     Priority: Minor
>  Attachments: AbstractStringBuilder.java, SB.diff
>
> The j.l.StringBuilder was introduced in Java 1.5 mainly as a speedup replacement to heavily
synchronized j.l.StringBuffer. 
> However, current implementation of StringBuilder performs 2-4 times slower than StringBuffer.

> The following simple test demonstrates this:
> public class SPTest {
>  public static void main(String[] s) {
>   test1();
>   test2();
>  }
>  
>  static void test1() {
>   long t1 = System.currentTimeMillis();
>   StringBuilder sb1 = new StringBuilder(100000);
>   for(int i=0; i<10000; i++){
>     sb1.append("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
>   }
>   long t2 = System.currentTimeMillis();
>   
>   StringBuffer sb2 = new StringBuffer(100000);
>   for(int i=0; i<10000; i++){
>     sb2.append("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
>   }
>   long t3 = System.currentTimeMillis();
>   
>   System.out.println("append(String) test, ms");
>   System.out.println("\tStringBuilder : " + (t2-t1));
>   System.out.println("\tStringBuffer : " + (t3-t2));
>  }
>  
>  static void test2() {
>   long t1 = System.currentTimeMillis();
>   String s1 = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
>   for(int i=0; i<1000; i++){
>     s1 = new StringBuilder(s1).append("1234567890").toString();
>   }
>   long t2 = System.currentTimeMillis();
>   String s2 = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
>   for(int i=0; i<1000; i++){
>     s2 = new StringBuffer(s2).append("1234567890").toString();
>   }
>   long t3 = System.currentTimeMillis();
>   System.out.println("constructor(String) test, ms");
>   System.out.println("\tStringBuilder : " + (t2-t1));
>   System.out.println("\tStringBuffer : " + (t3-t2));
>  }
> }
> Typical output on J9vm, interpreter mode:
> ---------------------------------
> append(String) test, ms
>  StringBuilder : 221
>  StringBuffer : 140
> constructor(String) test, ms
>  StringBuilder : 1051
>  StringBuffer : 291
> ---------------------------------
> J9vm, JIT mode:
> ---------------------------------
> append(String) test, ms
>  StringBuilder : 80
>  StringBuffer : 30
> constructor(String) test, ms
>  StringBuilder : 130
>  StringBuffer : 40
> --------------------------------
> Jrockit 1.5.0 output:
> --------------------------------
> append(String) test, ms
>  StringBuilder : 10
>  StringBuffer : 20
> constructor(String) test, ms
>  StringBuilder : 30
>  StringBuffer : 40
> Patch to fix this will follow.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message