Created
May 25, 2025 12:37
-
-
Save kimyerins/719f72a3915a1d1362ba2e2b605b0112 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 7. 대량 숫자 리스트의 합계 계산(김예린) | |
package task; | |
import java.util.concurrent.TimeUnit; | |
import java.util.stream.LongStream; | |
public class ParallelSumExampleTask { | |
private static final long TOTAL = 500_000_000L; | |
public static void main(String[] args) { | |
System.out.println("> Task : ParallelStreamSumExample.main()"); | |
long startTime = System.nanoTime(); | |
long sequentialSum = LongStream.rangeClosed(1, TOTAL).sum(); | |
long endTime = System.nanoTime(); | |
System.out.println("🚀 순차 스트림 합계: " + sequentialSum + | |
"(시간: " + TimeUnit.NANOSECONDS.toMillis(endTime - startTime) + "ms)"); | |
startTime = System.nanoTime(); | |
long parallelSum = LongStream.rangeClosed(1, TOTAL).parallel().sum(); | |
endTime = System.nanoTime(); | |
System.out.println("🔥 병렬 스트림 합계: " + parallelSum + | |
"(시간: " + TimeUnit.NANOSECONDS.toMillis(endTime - startTime) + "ms)"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment