public static void main(String[] args) { 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))); } catch(OutOfMemoryError e) { System.out.println("Insufficient memory"); System.exit(0); } } }
public static void main(String[] args) { Pizza za = new Pizza(0); System.out.println( Timer.duration(() -> { while(!za.complete()) za.next(); })); } }
public static void main(String[] args) { Timer timer = new Timer(); List<CompletableFuture<Pizza>> pizzas = IntStream.range(0, QUANTITY) .mapToObj(Pizza::new) .map(CompletablePizza::makeCF) .collect(Collectors.toList()); System.out.println(timer.duration()); pizzas.forEach(CompletablePizza::show); System.out.println(timer.duration()); } }
public static void main(String[] args) { long[] la = new long[SIZE]; Random r = new Random(); System.out.println("parallelSetAll: " + Timer.duration(() -> Arrays.parallelSetAll(la, n -> r.nextLong()))); System.out.println("setAll: " + Timer.duration(() -> Arrays.setAll(la, n -> r.nextLong()))); SplittableRandom sr = new SplittableRandom(); System.out.println("parallelSetAll: " + Timer.duration(() -> Arrays.parallelSetAll(la, n -> sr.nextLong()))); System.out.println("setAll: " + Timer.duration(() -> Arrays.setAll(la, n -> sr.nextLong()))); } }
static void timeTest(String id, long checkValue, LongSupplier operation) { System.out.print(id + ": "); Timer timer = new Timer(); long result = operation.getAsLong(); if(result == checkValue) System.out.println(timer.duration() + "ms"); else System.out.format("result: %d%ncheckValue: %d%n", result, checkValue); } public static final int SZ = 100_000_000;
public static void main(String[] args) { Timer timer = new Timer(); IntStream.range(0, QUANTITY) .mapToObj(Pizza::new) .parallel() .map(Pizza::roll) .map(Pizza::sauce) .map(Pizza::cheese) .map(Pizza::toppings) .map(Pizza::bake) .map(Pizza::slice) .map(Pizza::box) .forEach(za -> System.out.println(za)); System.out.println(timer.duration()); } }
public static void main(String[] args) { Timer timer = new Timer(); CompletableFuture<Machina> cf = CompletableFuture.completedFuture( new Machina(0)) .thenApplyAsync(Machina::work) .thenApplyAsync(Machina::work) .thenApplyAsync(Machina::work) .thenApplyAsync(Machina::work); System.out.println(timer.duration()); System.out.println(cf.join()); System.out.println(timer.duration()); } }
for(int i = 0; i < SIZE; i++) b[i] = new Thing4(); Timer timer = new Timer(); try( ByteArrayOutputStream buf = timer.duration() + " Milliseconds"); timer = new Timer(); Thing4[] d = new Thing4[SIZE]; for(int i = 0; i < SIZE; i++) System.out.println( "Duplication via cloning: " + timer.duration() + " Milliseconds");
public static void main(String[] args) throws IOException { Timer timer = new Timer(); List<String> primes = iterate(2, i -> i + 1) .parallel() // [1] .filter(ParallelPrime::isPrime) .limit(COUNT) .mapToObj(Long::toString) .collect(Collectors.toList()); System.out.println(timer.duration()); Files.write(Paths.get("primes.txt"), primes, StandardOpenOption.CREATE); } }