DAS_2024_1/emelyanov_artem_lab_6/Benchmark.java

28 lines
1.4 KiB
Java
Raw Permalink Normal View History

2024-10-19 14:17:22 +04:00
import java.util.concurrent.ExecutionException;
public class Benchmark {
public static void main(String[] args) throws ExecutionException, InterruptedException {
int[] sizes = {5, 7, 10};
for (int size : sizes) {
int[][] matrix = MatrixGenerator.generateMatrix(size);
// Последовательное вычисление
long startSequential = System.nanoTime();
double detSequential = DeterminantCalculator.calculateDeterminant(matrix, 1);
long endSequential = System.nanoTime();
System.out.println("Последовательно (" + size + "x" + size + "): " + (endSequential - startSequential) / 1_000_000 + " ms, детерминант: " + detSequential);
// Параллельное вычисление
for (int numThreads : new int[]{2, 4, 8}) {
long startParallel = System.nanoTime();
double detParallel = DeterminantCalculator.calculateDeterminant(matrix, numThreads);
long endParallel = System.nanoTime();
System.out.println("Параллельно (" + size + "x" + size + ", " + numThreads + " потоков): " +
(endParallel - startParallel) / 1_000_000 + " ms, детерминант: " + detParallel);
}
System.out.println("--------------------------------------------------");
}
}
}