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] Created: (HARMONY-589) [classlib][luni] java.lang.StringBuilder performs very slowly
Date Sat, 10 Jun 2006 07:05:29 GMT
[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


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