PrimeCheck.java
package ch.hslu.exercises.sw08.ex1;
import java.math.BigInteger;
import java.time.Duration;
import java.util.Random;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
/**
* 100 grosse Primzahlen finden.
*/
public final class PrimeCheck {
private static final Logger LOG = LoggerFactory.getLogger(PrimeCheck.class);
/**
* Privater Konstruktor.
*/
private PrimeCheck() {
}
/**
* Main-Demo.
*
* @param args not used.
*/
public static void main(String[] args) {
long start;
long stop;
PrimeCalculator primeCalculator = new PrimeCalculator(Runtime.getRuntime().availableProcessors() + 1);
start = System.nanoTime();
primeCalculator.calculatePrimesConcurrent();
stop = System.nanoTime();
LOG.info("Calculated primes concurrently in " + Duration.ofNanos(stop - start));
start = System.nanoTime();
primeCalculator.calculatePrimesSingleThreaded();
stop = System.nanoTime();
LOG.info("Calculated primes single threaded in " + Duration.ofNanos(stop - start));
}
}