forked from Alexey/DAS_2024_1
28 lines
1.4 KiB
Java
28 lines
1.4 KiB
Java
|
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("--------------------------------------------------");
|
||
|
}
|
||
|
}
|
||
|
}
|