DAS_2024_1/yakovleva_yulia_lab_5/MultiplicationLargeMatrices/MultiplicationLargeMatrices/MatrixMultiplicationBenchmark.cs
2024-10-25 18:12:36 +04:00

55 lines
1.7 KiB
C#

using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
public class MatrixMultiplicationBenchmark
{
private int[,] matrixA100, matrixB100;
private int[,] matrixA300, matrixB300;
private int[,] matrixA500, matrixB500;
// Количество потоков
private int threadCount = 5;
[GlobalSetup]
public void Setup()
{
matrixA100 = GenerateMatrix(100);
matrixB100 = GenerateMatrix(100);
matrixA300 = GenerateMatrix(300);
matrixB300 = GenerateMatrix(300);
matrixA500 = GenerateMatrix(500);
matrixB500 = GenerateMatrix(500);
}
private int[,] GenerateMatrix(int size)
{
var random = new Random();
var matrix = new int[size, size];
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
matrix[i, j] = random.Next(1, 10);
return matrix;
}
[Benchmark]
public void MultiplySequential100x100() => MatrixMultiplication.MultiplySequential(matrixA100, matrixB100);
[Benchmark]
public void MultiplyParallel100x100() => MatrixMultiplication.MultiplyParallel(matrixA100, matrixB100, threadCount);
[Benchmark]
public void MultiplySequential300x300() => MatrixMultiplication.MultiplySequential(matrixA300, matrixB300);
[Benchmark]
public void MultiplyParallel300x300() => MatrixMultiplication.MultiplyParallel(matrixA300, matrixB300, threadCount);
[Benchmark]
public void MultiplySequential500x500() => MatrixMultiplication.MultiplySequential(matrixA500, matrixB500);
[Benchmark]
public void MultiplyParallel500x500() => MatrixMultiplication.MultiplyParallel(matrixA500, matrixB500, threadCount);
}