mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix: optimize split for list
This commit is contained in:
@@ -1,12 +1,39 @@
|
||||
package cn.hutool.core.collection;
|
||||
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ListUtilTest {
|
||||
|
||||
@Test
|
||||
public void split() {
|
||||
List<String> list = new ArrayList<>();
|
||||
CollUtil.padRight(list, RandomUtil.randomInt(1000_0000, 1_0000_0000), "test");
|
||||
|
||||
int size = RandomUtil.randomInt(10, 1000);
|
||||
Console.log("\nlist size: {}", list.size());
|
||||
Console.log("partition size: {}\n", size);
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
|
||||
stopWatch.start("CollUtil#split");
|
||||
List<List<String>> CollSplitResult = CollUtil.split(list, size);
|
||||
stopWatch.stop();
|
||||
|
||||
stopWatch.start("ListUtil#split");
|
||||
List<List<String>> ListSplitResult = ListUtil.split(list, size);
|
||||
stopWatch.stop();
|
||||
|
||||
Assert.assertEquals(CollSplitResult, ListSplitResult);
|
||||
|
||||
Console.log(stopWatch.prettyPrint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterTest(){
|
||||
List<String> a = ListUtil.toLinkedList("1", "2", "3");
|
||||
|
Reference in New Issue
Block a user