forked from Alexey/DAS_2024_1
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strconv"
|
||
|
"time"
|
||
|
"zhimolostnova_anna_lab_6/alg"
|
||
|
"zhimolostnova_anna_lab_6/util"
|
||
|
)
|
||
|
|
||
|
// Функция для бенчмарка последовательного вычисления детерминанта
|
||
|
func benchmarkDeterminantSequential(sizes []int) {
|
||
|
for _, size := range sizes {
|
||
|
matrix := util.GenerateMatrix(size)
|
||
|
|
||
|
start := time.Now()
|
||
|
_ = alg.Determinant(matrix)
|
||
|
elapsed := time.Since(start)
|
||
|
|
||
|
fmt.Printf("Sequential determinant of matrix %sx%s took %s\n", strconv.Itoa(size), strconv.Itoa(size), elapsed)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Функция для бенчмарка параллельного вычисления детерминанта
|
||
|
func benchmarkDeterminantParallel(sizes []int, threadsList []int) {
|
||
|
for _, size := range sizes {
|
||
|
for _, threads := range threadsList {
|
||
|
matrix := util.GenerateMatrix(size)
|
||
|
|
||
|
start := time.Now()
|
||
|
_ = alg.DeterminantParallel(matrix, threads)
|
||
|
elapsed := time.Since(start)
|
||
|
|
||
|
fmt.Printf("Parallel determinant of matrix %sx%s with %d threads took %s\n", strconv.Itoa(size), strconv.Itoa(size), threads, elapsed)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
// Список размерностей матриц
|
||
|
sizes := []int{7, 8, 9}
|
||
|
|
||
|
// Список количества потоков для тестирования
|
||
|
threadsList := []int{2, 4, 6, 8}
|
||
|
|
||
|
// Запуск бенчмарков
|
||
|
fmt.Println("Sequential Benchmark:")
|
||
|
benchmarkDeterminantSequential(sizes)
|
||
|
|
||
|
fmt.Println("\nParallel Benchmark:")
|
||
|
benchmarkDeterminantParallel(sizes, threadsList)
|
||
|
}
|