< prev index next >

test/micro/org/openjdk/bench/java/lang/StringBuilders.java

Print this page
rev 54318 : 8221430: StringBuffer(CharSequence) constructor truncates when -XX:-CompactStrings specified
Reviewed-by: igerasim, rriggs
Contributed-by: Andrew Leonard <andrew_m_leonard@uk.ibm.com>

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -40,10 +40,16 @@
     private String[] strings;
     private String[] str3p4p2;
     private String[] str16p8p7;
     private String[] str3p9p8;
     private String[] str22p40p31;
+    private String[] str22p40p31;
+    private StringBuilder sbLatin1;
+    private StringBuilder sbUtf8;
+
+        return new StringBuilder("Latin1 string");
+    }
 
     @Setup
     public void setup() {
         strings = new String[]{"As", "your", "attorney,", "I",
                 "advise", "you", "to", "drive", "at", "top", "speed", "it'll",

@@ -51,10 +57,12 @@
                 "there", "before", "you", "turn", "into", "a", "wild", "animal."};
         str3p4p2 = new String[]{"123", "1234", "12"};
         str16p8p7 = new String[]{"1234567890123456", "12345678", "1234567"};
         str3p9p8 = new String[]{"123", "123456789", "12345678"};
         str22p40p31 = new String[]{"1234567890123456789012", "1234567890123456789012345678901234567890", "1234567890123456789012345678901"};
+        sbLatin1 = new StringBuilder("Latin1 string");
+        sbUtf8 = new StringBuilder("UTF-\uFF18 string");
     }
 
     /** StringBuilder wins over StringMaker. */
     @Benchmark
     public String concat3p4p2() throws Exception {

@@ -254,6 +262,26 @@
         result.append("stringelinglinglinglong");
         result.append('p');
         result.append("stringelinglinglinglong");
         return result.toString();
     }
+
+    @Benchmark
+    public StringBuilder fromLatin1String() {
+        return new StringBuilder("Latin1 string");
+    }
+
+    @Benchmark
+    public StringBuilder fromUtf8String() {
+        return new StringBuilder("UTF-\uFF18 string");
+    }
+
+    @Benchmark
+    public StringBuilder fromLatin1StringBuilder() {
+        return new StringBuilder(sbLatin1);
+    }
+
+    @Benchmark
+    public StringBuilder fromUtf8StringBuilder() {
+        return new StringBuilder(sbUtf8);
+    }
 }
< prev index next >