46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"time"
|
|
"zhimolostnova_anna_lab_5/util"
|
|
)
|
|
|
|
// Последовательное умножение двух квадратных матриц
|
|
func multiplyMatricesSequential(a, b [][]int) [][]int {
|
|
size := len(a)
|
|
result := make([][]int, size)
|
|
for i := range result {
|
|
result[i] = make([]int, size)
|
|
for j := 0; j < size; j++ {
|
|
for k := 0; k < size; k++ {
|
|
result[i][j] += a[i][k] * b[k][j]
|
|
}
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
// Функция для бенчмарка последовательного умножения
|
|
func benchmarkMatrixMultiplicationSequential(sizes []int) {
|
|
for _, size := range sizes {
|
|
matrixA := util.CreateMatrix(size)
|
|
matrixB := util.CreateMatrix(size)
|
|
|
|
start := time.Now()
|
|
_ = multiplyMatricesSequential(matrixA, matrixB)
|
|
elapsed := time.Since(start)
|
|
|
|
fmt.Printf("Sequential multiplication of matrix %sx%s took %s\n", strconv.Itoa(size), strconv.Itoa(size), elapsed)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
// Список размерностей матриц
|
|
sizes := []int{100, 300, 500}
|
|
|
|
// Запуск бенчмарка
|
|
benchmarkMatrixMultiplicationSequential(sizes)
|
|
}
|