38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
|
const { determinant, determinantParallel } = require('./matrix.operations');
|
||
|
|
||
|
function generateMatrix(size) {
|
||
|
const matrix = new Array(size);
|
||
|
for (let i = 0; i < size; i++) {
|
||
|
matrix[i] = new Array(size);
|
||
|
for (let j = 0; j < size; j++) {
|
||
|
matrix[i][j] = Math.floor(Math.random() * 20) - 10;
|
||
|
}
|
||
|
}
|
||
|
return matrix;
|
||
|
}
|
||
|
|
||
|
async function benchmark() {
|
||
|
const sizes = [5, 7, 10];
|
||
|
const numThreads = [2, 4, 8];
|
||
|
|
||
|
for (const size of sizes) {
|
||
|
const matrix = generateMatrix(size);
|
||
|
|
||
|
console.log(`\nМатрица (${size}x${size}):`);
|
||
|
|
||
|
console.time('Последовательно');
|
||
|
const detSeq = determinant(matrix);
|
||
|
console.timeEnd('Последовательно');
|
||
|
console.log(`Детерминант: ${detSeq}`);
|
||
|
|
||
|
for (const threads of numThreads) {
|
||
|
console.time(`Параллельно (${threads} потоков)`);
|
||
|
const detPar = await determinantParallel(matrix, threads);
|
||
|
console.timeEnd(`Параллельно (${threads} потоков)`);
|
||
|
console.log(`Детерминант: ${detPar}`);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
benchmark();
|