diff --git a/Lab2/Lab2.csproj b/Lab2/Lab2.csproj
new file mode 100644
index 0000000..c73e0d1
--- /dev/null
+++ b/Lab2/Lab2.csproj
@@ -0,0 +1,8 @@
+
+
+
+ Exe
+ netcoreapp3.1
+
+
+
diff --git a/Lab2/Program.cs b/Lab2/Program.cs
new file mode 100644
index 0000000..a9d7ecd
--- /dev/null
+++ b/Lab2/Program.cs
@@ -0,0 +1,116 @@
+using System;
+using System.Reflection;
+
+namespace Lab2
+{
+ internal class Program
+ {
+ public static uint counter = 0;
+
+ public static long methodToAnalysis1(int[] arr)
+ {
+ long n = arr.Length;
+ long k = n;
+ for (int i = 0; i < n; i++)
+ {
+ counter += 1;
+ if (arr[i] > 0)
+ {
+ for (int j = 0; j < n * n / 2; j++)
+ {
+ k -= 2;
+ counter += 1;
+ }
+ for (int j = 0; j < n * n / 2; j++)
+ {
+ k += 3;
+ counter += 1;
+ }
+ }
+ }
+ return k;
+ }
+
+ public static long methodToAnalysis2(int n, int[] arr)
+ {
+ long k = 0;
+ for (int i = 0; i < n; i++)
+ {
+ counter += 1;
+ k += arr[i] + FF4(i, arr);
+ }
+
+ return k;
+ }
+ public static long methodToAnalysis2(int[] arr)
+ {
+ return methodToAnalysis2(arr.Length, arr);
+ }
+
+ public static long FF4(int n, int[] arr)
+ {
+ if (n > 0 && arr.Length > n && arr[n] < 0)
+ {
+ counter += 1;
+ return FF4(n / 2, arr) + FF4(n / 3, arr);
+ }
+ return n;
+ }
+
+ public static double TestFunc(Func T, uint n, int value)
+ {
+ int[] data = new int[n];
+ for (int i = 0; i < n; i++)
+ {
+ data[i] = value;
+ }
+
+ var before = DateTime.Now;
+ counter = 0;
+ T(data);
+ var duration = DateTime.Now - before;
+ return duration.TotalSeconds;
+ }
+
+ static void TestMethod(Func F, string format, int bestValue, uint[] best, int worstValue, uint[] worst)
+ {
+ Console.WriteLine("- Best:");
+ foreach (var n in best)
+ {
+ double time = TestFunc(F, n, bestValue);
+ Console.WriteLine(format, n, time, counter);
+ }
+ Console.WriteLine("- Worst:");
+ foreach (var n in worst)
+ {
+ double time = TestFunc(F, n, worstValue);
+ Console.WriteLine(format, n, time, counter);
+ }
+ }
+
+
+ static void Main(string[] args)
+ {
+ string format = " F({0}) => {1}s {2}i";
+ //string format = "{1} {2}";
+
+ /*
+ Console.WriteLine("methodToAnalysis1:");
+ TestMethod(
+ methodToAnalysis1,
+ format,
+ -1, new uint[] { 10000, 100000000, 300000000, 600000000, 900000000 },
+ 1, new uint[] { 500, 600, 700, 800, 1000 }
+ );
+ */
+
+ Console.WriteLine("methodToAnalysis2:");
+ TestMethod(
+ methodToAnalysis2,
+ format,
+ 1, new uint[] { 10000, 100000000, 300000000, 600000000, 900000000 },
+ -1, new uint[] { 10000, 20000, 30000, 50000, 100000 }
+ );
+ }
+ }
+}
diff --git a/Labs.sln b/Labs.sln
index f7c0701..78fd219 100644
--- a/Labs.sln
+++ b/Labs.sln
@@ -5,6 +5,8 @@ VisualStudioVersion = 17.1.32328.378
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab1", "Lab1\Lab1.csproj", "{497767A1-722A-4F48-86E5-C2AE6E0B9C9A}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab2", "Lab2\Lab2.csproj", "{6AF5D775-08B9-4D4F-9E2E-116C551D0581}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
{497767A1-722A-4F48-86E5-C2AE6E0B9C9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{497767A1-722A-4F48-86E5-C2AE6E0B9C9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{497767A1-722A-4F48-86E5-C2AE6E0B9C9A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6AF5D775-08B9-4D4F-9E2E-116C551D0581}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6AF5D775-08B9-4D4F-9E2E-116C551D0581}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6AF5D775-08B9-4D4F-9E2E-116C551D0581}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6AF5D775-08B9-4D4F-9E2E-116C551D0581}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE