OnJava8-Examples/validating/BadMicroBenchmark.java

29 lines
845 B
Java
Raw Permalink Normal View History

2016-08-29 07:27:53 -06:00
// validating/BadMicroBenchmark.java
// (c)2021 MindView LLC: see Copyright.txt
2016-01-25 18:05:55 -08:00
// 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.
// {ExcludeFromTravisCI}
2016-01-25 18:05:55 -08:00
import java.util.*;
import onjava.Timer;
2016-01-25 18:05:55 -08:00
public class BadMicroBenchmark {
2016-09-28 12:54:00 -06:00
static final int SIZE = 250_000_000;
2016-01-25 18:05:55 -08:00
public static void main(String[] args) {
2016-11-26 10:20:48 -08:00
try { // For machines with insufficient memory
long[] la = new long[SIZE];
System.out.println("setAll: " +
Timer.duration(() ->
Arrays.setAll(la, n -> n)));
System.out.println("parallelSetAll: " +
Timer.duration(() ->
Arrays.parallelSetAll(la, n -> n)));
2016-11-26 10:20:48 -08:00
} catch(OutOfMemoryError e) {
System.out.println("Insufficient memory");
System.exit(0);
}
2016-01-25 18:05:55 -08:00
}
}
/* Output:
Insufficient memory
2016-01-25 18:05:55 -08:00
*/