DAS_2024_1/emelyanov_artem_lab_5/Benchmark.java

23 lines
1.1 KiB
Java
Raw Permalink Normal View History

2024-10-18 17:41:49 +04:00
public class Benchmark {
public static void main(String[] args) {
int[] sizes = {100, 300, 500};
for (int size : sizes) {
int[][] matrixA = MatrixGenerator.generateMatrix(size);
int[][] matrixB = MatrixGenerator.generateMatrix(size);
long startSequential = System.nanoTime();
MatrixMultiplication.multiply(matrixA, matrixB, 1);
long endSequential = System.nanoTime();
System.out.println("Последовательно (" + size + "x" + size + "): " + (endSequential - startSequential) / 1_000_000 + " ms");
for (int numThreads : new int[]{2, 4, 8}) {
long startParallel = System.nanoTime();
MatrixMultiplication.multiply(matrixA, matrixB, numThreads);
long endParallel = System.nanoTime();
System.out.println("Параллельно (" + size + "x" + size + ", " + numThreads + " потоков): " +
(endParallel - startParallel) / 1_000_000 + " ms");
}
}
}
}