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