Created
June 3, 2020 17:24
-
-
Save comchangs/ace4e5643ca33ccce10e384a7ebafb28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.stream.Stream; | |
public class StreamTest { | |
private static int MAX_ITERATION = 3_000; | |
public static void main(String[] args) { | |
List<String> list = new LinkedList<>(); | |
for (int i = 0; i < MAX_ITERATION; i++) { | |
list.add(String.valueOf(i)); | |
} | |
long start = 0, end = 0; | |
long sum[] = {0}; | |
start = System.currentTimeMillis(); | |
Stream<String> streamToParallel = list.stream().parallel(); | |
streamToParallel.forEach(value -> { | |
long s = System.currentTimeMillis(); | |
print(value); | |
long e = System.currentTimeMillis() - s; | |
//System.out.println(e); | |
sum[0] = sum[0] + e; | |
System.out.println(sum[0]); | |
}); | |
end = System.currentTimeMillis(); | |
System.out.println("병렬처리: " + (end - start)); //병렬처리: 4282 | |
} | |
public static void print(String str) { | |
System.out.println(str+ " : "+Thread.currentThread().getName()); | |
try { | |
Thread.sleep(10); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment