1 package ch.hslu.exercises.sw08.ex1;
2
3 import java.math.BigInteger;
4 import java.time.Duration;
5 import java.util.Random;
6
7 import org.slf4j.LoggerFactory;
8 import org.slf4j.Logger;
9
10
11
12
13 public final class PrimeCheck {
14
15 private static final Logger LOG = LoggerFactory.getLogger(PrimeCheck.class);
16
17
18
19
20 private PrimeCheck() {
21 }
22
23
24
25
26
27
28 public static void main(String[] args) {
29 long start;
30 long stop;
31 PrimeCalculator primeCalculator = new PrimeCalculator(Runtime.getRuntime().availableProcessors() + 1);
32 start = System.nanoTime();
33 primeCalculator.calculatePrimesConcurrent();
34 stop = System.nanoTime();
35 LOG.info("Calculated primes concurrently in " + Duration.ofNanos(stop - start));
36
37 start = System.nanoTime();
38 primeCalculator.calculatePrimesSingleThreaded();
39 stop = System.nanoTime();
40 LOG.info("Calculated primes single threaded in " + Duration.ofNanos(stop - start));
41
42 }
43 }