-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
77 lines (63 loc) · 2.93 KB
/
Copy pathProgram.cs
File metadata and controls
77 lines (63 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
namespace LabPartIII;
class Program
{
static void Main()
{
int maxN = 2000;
Benchmark.Initialize(maxN);
var vectorAlgorithms = new Dictionary<string, Func<double[], object>>
{
{ "LinearSum", Algorithms.LinearSum },
{ "CountDistinct", Algorithms.CountDistinct },
{ "MergeSort", Algorithms.MergeSortWrapper },
{ "BubbleSort", Algorithms.BubbleSort },
{ "NaivePower", Algorithms.NaivePower },
{ "FastPower", Algorithms.FastPower }
};
var stringAlgorithms = new Dictionary<string, Func<string, object>>
{
{ "KMPSearch", Algorithms.KMPSearch },
{ "NaiveStringSearch", Algorithms.NaiveStringSearch }
};
var vectorResults = new Dictionary<string, double[]>();
foreach (var kv in vectorAlgorithms) vectorResults[kv.Key] = new double[maxN + 1];
var stringResults = new Dictionary<string, double[]>();
foreach (var kv in stringAlgorithms) stringResults[kv.Key] = new double[maxN + 1];
Console.WriteLine("Измерения векторных алгоритмов...");
for (int n = 1; n <= maxN; n++)
{
foreach (var kv in vectorAlgorithms)
vectorResults[kv.Key][n] = Benchmark.MeasureTime(kv.Value, n);
if (n % 200 == 0) Console.WriteLine($"Векторы: n={n}");
}
Console.WriteLine("\nИзмерения строковых алгоритмов...");
for (int n = 1; n <= maxN; n++)
{
foreach (var kv in stringAlgorithms)
stringResults[kv.Key][n] = Benchmark.MeasureTimeString(kv.Value, n);
if (n % 200 == 0) Console.WriteLine($"Строки: n={n}");
}
CsvUtils.SaveCsv(vectorResults, "results_vectors.csv");
CsvUtils.SaveCsv(stringResults, "results_strings.csv");
Console.WriteLine("\nИзмерения умножения матриц...");
var matrixResults = new List<(int m, int n, double time)>();
int[] sizes = { 10, 20, 40, 60, 80, 100, 150, 200 };
foreach (int m in sizes)
{
foreach (int n in sizes)
{
double time = Benchmark.MeasureTimeMatrix(Algorithms.MatrixMultiplication, m, n);
matrixResults.Add((m, n, time));
Console.WriteLine($"m={m}, n={n}, time={time:F3} ms");
}
}
CsvUtils.SaveMatrixCsv(matrixResults, "results_matrices.csv");
// Построение графиков
Plotter.PlotVectorAlgorithms(vectorResults, "vector_algorithms.png");
Plotter.PlotStringAlgorithms(stringResults, "string_algorithms.png");
Plotter.PlotMatrixHeatmap(matrixResults, "matrix_heatmap.png");
Console.WriteLine("\nВсе данные сохранены, графики построены.");
}
}