In Fig. 17.24 , we implemented a stream pipeline that rolled a die 60,000,000 times using values

Question:

In Fig. 17.24 , we implemented a stream pipeline that rolled a die 60,000,000 times using values produced by SecureRandom method ints.

Use the same timing techniques you used in Exercise 17.25 to time the original stream pipeline’s operation, then perform and time the operation using a parallel stream. Any improvement?

Exercise 17.25

In Fig. 17.24, we implemented a stream pipeline that rolled a die 60,000,000 times using values produced by SecureRandom method ints. Package java.time contains types Instant and Duration that you can use to capture the time before and after evaluating the stream pipeline, then calculate the difference between the Instants to determine the total time. Use Instant’s static method now to get the current time. To determine the difference between two Instants, use class Duration’s static method between, which returns a Duration object containing the time difference. Duration provides methods like toMillis to return a duration in milliseconds. Use these timing techniques to time the original stream pipeline’s operation, then do so again using class Random from package java.util, rather than SecureRandom.

Fig. 17.24

// Fig. 17.24: RandomIntStream.java // Rolling a die 60,000,000 times with streams 3 import

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Java How To Program Late Objects Version

ISBN: 9780136123712

8th Edition

Authors: Paul Deitel, Deitel & Associates

Question Posted: