OnJava8-Examples/validating/BadMicroBenchmark3.java

34 lines
987 B
Java
Raw Normal View History

2016-08-29 07:27:53 -06:00
// validating/BadMicroBenchmark3.java
2016-01-25 18:05:55 -08:00
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
2016-09-23 13:23:35 -06:00
// Visit http://OnJava8.com for more book information.
2016-01-25 18:05:55 -08:00
// Relying on a common resource
import java.util.*;
public class BadMicroBenchmark3 {
static final int SIZE = 20_000_000;
public static void main(String[] args) {
long[] la = new long[SIZE];
Random r = new Random();
System.out.print("parallelSetAll: ");
Time.it(() ->
2016-01-25 18:05:55 -08:00
Arrays.parallelSetAll(la, n -> r.nextLong()));
System.out.print("setAll: ");
Time.it(() ->
2016-01-25 18:05:55 -08:00
Arrays.setAll(la, n -> r.nextLong()));
SplittableRandom sr = new SplittableRandom();
System.out.print("parallelSetAll: ");
Time.it(() ->
2016-01-25 18:05:55 -08:00
Arrays.parallelSetAll(la, n -> sr.nextLong()));
System.out.print("setAll: ");
Time.it(() ->
2016-01-25 18:05:55 -08:00
Arrays.setAll(la, n -> sr.nextLong()));
}
}
/* Output:
2016-07-27 11:12:11 -06:00
parallelSetAll: 4540
setAll: 1540
parallelSetAll: 398
setAll: 739
2016-01-25 18:05:55 -08:00
*/