@@ -0,0 +1,2443 @@
+package com.yuzhouwan.hacker.lambda;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Random;%0A%0A/**%0A * Copyright @ 2017 yuzhouwan.com%0A * All right reserved.%0A * Function%EF%BC%9AStream Performance%0A *%0A * @author Benedict Jin%0A * @since 2017/5/2%0A */%0Apublic class StreamPerformance %7B%0A%0A    private static final Random r = new Random();%0A%0A    public static void main(String%5B%5D args) %7B%0A        // -Xmx2G -Xms2G -Xmn1G -XX:+AlwaysPreTouch%0A        /*%0A        Simple Loop:%0A            ArrayList: 1 elements, Count: 0, Time: 25193 ns%0A        Lambda Stream:%0A            ArrayList: 1 elements, Count: 0, Time: 19283 ns%0A        Simple Loop:%0A            ArrayList: 10 elements, Count: 26, Time: 3111 ns%0A        Lambda Stream:%0A            ArrayList: 10 elements, Count: 26, Time: 8398 ns%0A        Simple Loop:%0A            ArrayList: 100 elements, Count: 2589, Time: 21149 ns%0A        Lambda Stream:%0A            ArrayList: 100 elements, Count: 2589, Time: 26126 ns%0A        Simple Loop:%0A            ArrayList: 1000 elements, Count: 254389, Time: 146490 ns%0A        Lambda Stream:%0A            ArrayList: 1000 elements, Count: 254389, Time: 164218 ns%0A        Simple Loop:%0A            ArrayList: 10000 elements, Count: 24861987, Time: 742710 ns%0A        Lambda Stream:%0A            ArrayList: 10000 elements, Count: 24861987, Time: 471192 ns%0A         */%0A        performance(0);     // initialization resource%0A        performance(1);%0A        performance(10);%0A        performance(100);%0A        performance(1000);%0A        performance(1_0000);%0A    %7D%0A%0A    private static void performance(int len) %7B%0A        ArrayList%3CInteger%3E list = new ArrayList%3C%3E(len);%0A        for (int i = 1; i %3C= len; i++) %7B%0A            list.add(r.nextInt(i));%0A        %7D%0A        int countLoop = 0, countStream = 0;%0A        long startTime, endTime;%0A%0A        startTime = System.nanoTime();%0A        for (Integer i : list) %7B%0A            countLoop += i;%0A        %7D%0A        endTime = System.nanoTime();%0A        System.out.println(String.format(%22Simple Loop:%5Cr%5Cn%5CtArrayList: %25d elements, Count: %25d, Time: %25d ns%22,%0A                len, countLoop, (endTime - startTime)));%0A%0A        startTime = System.nanoTime();%0A        countStream = list.stream().reduce(countStream, (acc, e) -%3E acc + e);%0A        endTime = System.nanoTime();%0A%0A        System.out.println(String.format(%22Lambda Stream:%5Cr%5Cn%5CtArrayList: %25d elements, Count: %25d, Time: %25d ns%22,%0A                len, countStream, (endTime - startTime)));%0A        list.clear();%0A    %7D%0A%7D%0A

add Stream Performance Test