package zutil.benchmark; import com.carrotsearch.junitbenchmarks.BenchmarkOptions; import com.carrotsearch.junitbenchmarks.BenchmarkRule; import org.junit.Rule; import org.junit.Test; import java.util.ArrayList; import java.util.regex.Pattern; import static org.junit.Assert.assertEquals; /** * Created by Ziver on 2016-07-07. */ public class StringSplitBenchmark { public static final int TEST_EXECUTIONS = 200000; @Rule public BenchmarkRule benchmarkRun = new BenchmarkRule(); private static String delimiter = ","; private static String str = "aaa,aaaaaa,aaaaaa,aa,a,a,a,bb,bbb,aaaaaaaaa,a,a,aaa"; @Test public void stringSplit(){ for(int i=0; i splitList = new ArrayList<>(); int from = 0, to = 0; while (to >= 0) { to = str.indexOf(delimiter, from + 1); if (to < 0) splitList.add(str.substring(from)); else splitList.add(str.substring(from, to)); from = to; } assertSplit(splitList.toArray(new String[splitList.size()])); } } public void assertSplit(String[] str){ assertEquals(13,str.length); } }