import java.util.concurrent.ExecutionException;
import java.util.Random;

public class Main {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        int size = 10000; // size matrix
        int[][] matrix = generateMatrix(size);

        // SingleThreaded algorithm
        long startTime = System.nanoTime();
        double singleThreadedResult = SingleThreadedAverage.calculate(matrix);
        long endTime = System.nanoTime();
        System.out.println("Single-threaded result: " + singleThreadedResult);
        System.out.println("Single-threaded time: " + (endTime - startTime) / 1_000_000 + " ms");

        // ThreadPoolExecutor algorithm
        startTime = System.nanoTime();
        double threadPoolResult = ThreadPoolAverage.calculate(matrix, 4);
        endTime = System.nanoTime();
        //System.out.println("ThreadPool result: " + threadPoolResult);
        System.out.println("ThreadPoolExecutor time: " + (endTime - startTime) / 1_000_000 + " ms");

        // ForkJoinPool algorithm
        startTime = System.nanoTime();
        double forkJoinResult = ForkJoinAverage.calculate(matrix);
        endTime = System.nanoTime();
        //System.out.println("ForkJoin result: " + forkJoinResult);
        System.out.println("ForkJoinPool time: " + (endTime - startTime) / 1_000_000 + " ms");

    }
    private static int[][] generateMatrix(int size) {
        int[][] matrix = new int[size][size];
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                matrix[i][j] = random.nextInt(1000);
            }
        }
        return matrix;
    }
}