Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.stream.IntStream;

public class Main {
    public static void main(String[] argv) {
        System.out.println("Benchmarking...");
        long t0 = System.nanoTime();

        int a[] = IntStream.range(0, 1_000_000).filter(p -> p % 2 == 0).toArray();
        long t1 = System.nanoTime();

        int b[] = IntStream.range(0, 1_000_000).parallel().filter(p -> p % 2 == 0).toArray();
        long t2 = System.nanoTime();

        System.out.printf("serial: %.2fs, parallel %.2fs%n", (t1 - t0) * 1e-9, (t2 - t1) * 1e-9);
    }
}