DAS_2024_1/bondarenko_max_lab_5/benchmark.js

30 lines
964 B
JavaScript

const { multiplyMatricesSequential, multiplyMatricesParallel } = require('./matrix.operations');
function generateMatrix(size) {
return Array.from({ length: size }, () => Array.from({ length: size }, () => Math.floor(Math.random() * 100)));
}
async function benchmark() {
const sizes = [100, 300, 500];
const numThreads = [1, 2, 4, 8];
for (const size of sizes) {
const A = generateMatrix(size);
const B = generateMatrix(size);
console.log(`\nMatrix size: ${size}x${size}`);
console.time(`Sequential (${size}x${size})`);
multiplyMatricesSequential(A, B);
console.timeEnd(`Sequential (${size}x${size})`);
for (const threads of numThreads) {
console.time(`Parallel (${size}x${size}, ${threads} threads)`);
await multiplyMatricesParallel(A, B, threads);
console.timeEnd(`Parallel (${size}x${size}, ${threads} threads)`);
}
}
}
benchmark();