YuyuZha0 commented on issue #443: Optimize string split methods: 1. Use ThreadLocal to make reuse of th… URL: https://github.com/apache/commons-lang/pull/443#issuecomment-523333364 On my Mac(Intel Core i5, 2.3GHz, openjdk version "11.0.2"), It brings about 17% of performance improvation: ``` Benchmark Mode Cnt Score Error Units StringSplitBenchmark.testCommonsLang3Split avgt 25 928.749 ± 11.299 ns/op StringSplitBenchmark.testFastSplitUtils avgt 25 771.481 ± 19.010 ns/op ``` Here is the test cases: ``` @OutputTimeUnit(TimeUnit.NANOSECONDS) @BenchmarkMode(Mode.AverageTime) @Warmup(iterations = 5, time = 5) @Measurement(iterations = 5, time = 5) public class StringSplitBenchmark { private static final char separator = '@'; @Benchmark public String[] testCommonsLang3Split(StringSupplier stringSupplier) { return StringUtils.splitPreserveAllTokens(stringSupplier.get(), separator); } @Benchmark public String[] testFastSplitUtils(StringSupplier stringSupplier) { return FastSplitUtils.splitPreserveAllTokens(stringSupplier.get(), separator); } @State(Scope.Thread) public static class StringSupplier implements Supplier<String> { private final String[] array; private int index = 0; public StringSupplier() { List<String> list = new ArrayList<>(1000); ThreadLocalRandom random = ThreadLocalRandom.current(); for (int i = 0; i < 1000; i++) { String s = StringUtils.join( random.ints(25).toArray(), separator ); list.add(s); } this.array = list.toArray(new String[0]); } @Override public String get() { if (index >= array.length) index = 0; return array[index++]; } } } ``` I think this may be helpful to you @kinow
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
