|
|
|
@ -13,26 +13,35 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
public class StreamTest {
|
|
|
|
|
|
|
|
|
|
private static Set<String> uids;
|
|
|
|
|
|
|
|
|
|
// private static Set<String> uids;
|
|
|
|
|
private static List<String> base;
|
|
|
|
|
|
|
|
|
|
private static Set<String> equals;
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
uids = new HashSet<>(50_0000);
|
|
|
|
|
uids.add("111111111111111111111111");
|
|
|
|
|
uids.add("111111111111111111111112");
|
|
|
|
|
for (int i = 0; i < 500000; i++) {
|
|
|
|
|
uids.add(RandomUtil.randomString(24));
|
|
|
|
|
}
|
|
|
|
|
uids.add("111111111111111111111113");
|
|
|
|
|
// uids = new HashSet<>(50_0000);
|
|
|
|
|
// uids.add("111111111111111111111111");
|
|
|
|
|
// uids.add("111111111111111111111112");
|
|
|
|
|
// for (int i = 0; i < 500000; i++) {
|
|
|
|
|
// uids.add(RandomUtil.randomString(24));
|
|
|
|
|
// }
|
|
|
|
|
// uids.add("111111111111111111111113");
|
|
|
|
|
|
|
|
|
|
base = new ArrayList<>(2000_0000);
|
|
|
|
|
base = new ArrayList<>(1_0000);
|
|
|
|
|
base.add("111111111111111111111111");
|
|
|
|
|
base.add("111111111111111111111112");
|
|
|
|
|
for (int i = 0; i < 2000_0000; i++) {
|
|
|
|
|
for (int i = 0; i < 20_0000; i++) {
|
|
|
|
|
base.add(RandomUtil.randomString(24));
|
|
|
|
|
}
|
|
|
|
|
base.add("111111111111111111111113");
|
|
|
|
|
|
|
|
|
|
equals = new HashSet<>(1_0000);
|
|
|
|
|
equals.add("111111111111111111111111");
|
|
|
|
|
equals.add("111111111111111111111112");
|
|
|
|
|
for (int i = 0; i < 20_0000; i++) {
|
|
|
|
|
equals.add(RandomUtil.randomString(24));
|
|
|
|
|
}
|
|
|
|
|
equals.add("111111111111111111111113");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -43,13 +52,33 @@ public class StreamTest {
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testFilter(){
|
|
|
|
|
// Long start = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
|
|
// System.out.println(" start , " + start);
|
|
|
|
|
//// Set<String> collect = uids.stream().parallel().filter(base::contains).collect(Collectors.toSet());
|
|
|
|
|
// Set<String> collect = base.stream().parallel().filter(uids::contains).collect(Collectors.toSet()); // 2119 334
|
|
|
|
|
//
|
|
|
|
|
// System.out.println("uids size :" + uids.size() + ", base size: " + base.size() + ", 重复"+ collect.size());
|
|
|
|
|
// Long end = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
|
|
// System.out.println(" end, "+ end +", cost , " + (end - start));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 测试去重写法 - c测试想等的情况
|
|
|
|
|
* 测试结论:
|
|
|
|
|
* 1. 一定要在大集合里面去重小集合
|
|
|
|
|
* 2. 数据结构大集合采用 List 小集合采用 Set
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testFilter2(){
|
|
|
|
|
Long start = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
|
|
System.out.println(" start , " + start);
|
|
|
|
|
// Set<String> collect = uids.stream().parallel().filter(base::contains).collect(Collectors.toSet());
|
|
|
|
|
Set<String> collect = base.stream().parallel().filter(uids::contains).collect(Collectors.toSet()); // 2119 334
|
|
|
|
|
Set<String> collect = base.stream().parallel().filter(equals::contains).collect(Collectors.toSet()); // 2119 334
|
|
|
|
|
|
|
|
|
|
System.out.println("uids size :" + uids.size() + ", base size: " + base.size() + ", 重复"+ collect.size());
|
|
|
|
|
System.out.println("equals size :" + equals.size() + ", base size: " + base.size() + ", 重复"+ collect.size());
|
|
|
|
|
Long end = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
|
|
System.out.println(" end, "+ end +", cost , " + (end - start));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|