java8新特性:并行流与顺序流
1、使用顺序流计算0到1亿之和:
@Test
public void test10() {
Instant start = Instant.now();
LongStream.rangeClosed(1,10000000000000L).reduce(0,Long::sum);
System.out.println("系统执行时间:"+Duration.between(start,Instant.now()).toMillis());
}

2、执行程序,查看运行时间:

3、使用并行流计算0到1亿之和:
@Test
public void test11() {
Instant start = Instant.now();
LongStream.rangeClosed(1,10000000000000L).parallel().reduce(0,Long::sum);
System.out.println("系统执行时间:"+Duration.between(start,Instant.now()).toMillis());
}

4、执行程序,查看并行流运行时间:

5、并行流计算集合数量
public void test12() {
System.out.println(deptList.stream().parallel().count());
}

6、执行程序,查看程序运行时间:

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:130
阅读量:105
阅读量:123
阅读量:98
阅读量:185