public static void main(String[] args) { Timer timer = new Timer(); CompletableFuture<Machina> cf = CompletableFuture.completedFuture( new Machina(0)) .thenApply(Machina::work) .thenApply(Machina::work) .thenApply(Machina::work) .thenApply(Machina::work); System.out.println(timer.duration()); } }
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) { 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()); } }
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() // [1] .forEach(za -> { while(!za.complete()) za.next(); }); 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()); } }
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); } }