amarkevich opened a new pull request #479: String.split via fastpath instead of 
precompiled Pattern
URL: https://github.com/apache/cxf/pull/479
 
 
   
https://stackoverflow.com/questions/29393086/pattern-split-slower-than-string-split
   
   benchmark:
   
   `public class SplitTest {
   
       private static final int CNT = 131072;
       private static String[] STR = new String[CNT];
       private static final String SEPARATOR = " ";
       static {
           for (int i = 0; i < CNT; ++i) {
               STR[i] = i + SEPARATOR + i;
           }
       }
   
       @org.junit.Test
       public void stringSplit() {
           metrics("String.split", s -> s.split(SEPARATOR));
       }
   
       @org.junit.Test
       public void pattern() {
           metrics("Pattern", 
java.util.regex.Pattern.compile(SEPARATOR)::split);
       }
   
       private static void metrics(String label, Function<String, String[]> f) {
           Runtime.getRuntime().gc();
           long m = Runtime.getRuntime().freeMemory();
           long t = System.currentTimeMillis();
           for (int i = 0; i < CNT; ++i) {
               org.junit.Assert.assertSame(2, f.apply(STR[i]).length);
           }
           System.out.println(label + ": "
                   + ((m - Runtime.getRuntime().freeMemory()) / 1000000) + " MB 
"
                   + (System.currentTimeMillis() - t) + " ms");
       }
   
       public static void main(String[] args) {
           SplitTest splitTest = new SplitTest();
           for (int i = 0; i < 10; ++i) {
               splitTest.stringSplit();
               splitTest.pattern();
           }
       }
   }`
   
   results using java version "1.8.0_192":
   `String.split: 33 MB 16 ms
   Pattern: 57 MB 47 ms
   `

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to