static void BenchPar() { for (int i = 1; i <= 5; i++) { int[] X1 = Data.GenRandomArray(2000 * i); int[] Y1 = Data.GenRandomArray(2000 * i); int m = X1.Length; int n = Y1.Length; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); int [,] W = MWCS_BottomUp(X1, Y1); Console.WriteLine("Dynamic: " + W[m, n]); stopwatch.Stop(); TimeSpan dTime = stopwatch.Elapsed; stopwatch.Restart(); Console.WriteLine("Parallel: " + MWCS_Parallel(X1, Y1, W) + "\n"); stopwatch.Stop(); TimeSpan pTime = stopwatch.Elapsed; stopwatch.Reset(); Console.WriteLine("N = " + 20000 * i); Console.WriteLine("Dynamic: " + dTime); Console.WriteLine("Parallel: " + pTime + "\n"); } }
static void Bench() { for (int i = 0; i < 5; i++) { int[] X1 = Data.GenRandomArray(10 + i * 3); int[] Y1 = Data.GenRandomArray(10 + i * 3); Stopwatch stopwatch = new Stopwatch(); int m = X1.Length; int n = Y1.Length; stopwatch.Start(); int[,] W = MWCS_BottomUp(X1, Y1); Console.WriteLine((i + 1) + "Dynamic: " + W[m, n]); stopwatch.Stop(); TimeSpan dTime = stopwatch.Elapsed; stopwatch.Restart(); Console.WriteLine((i + 1) + "Recursive: " + MWCS_Recurssive(X1, Y1, m, n) + "\n"); stopwatch.Stop(); TimeSpan rTime = stopwatch.Elapsed; Console.WriteLine((i + 1) + " - Recursive vs. Dynamic Time"); Console.WriteLine("Recursive: " + rTime); Console.WriteLine("Dynamic: " + dTime + "\n"); } }
static void BenchCR() { for (int i = 1; i <= 5; i++) { Stopwatch stopwatch = new Stopwatch(); int[] arr = Data.GenRandomArray(100 * i); stopwatch.Start(); CutRod(arr, arr.Length); stopwatch.Stop(); TimeSpan time = stopwatch.Elapsed; Console.WriteLine("N - " + (100 * i) + " Time: " + time); stopwatch.Reset(); } }
static void Main(string[] args) { int[] X1 = new int[] { 1, 5, 5, 2, 1, 8 }; int[] Y1 = new int[] { 5, 3, 2, 3, 1, 6, 8 }; //int[] X1 = Data.GenRandomArray(15); //int[] Y1 = Data.GenRandomArray(15); Stopwatch stopwatch = new Stopwatch(); int m = X1.Length; int n = Y1.Length; //Bench(); //BenchCR(); //BenchCR(); BenchPar(); BenchPar(); Console.WriteLine("Uzduotis nr. 1\n"); stopwatch.Start(); int[,] W = MWCS_BottomUp(X1, Y1); Console.WriteLine("Dynamic: " + W[m, n]); stopwatch.Stop(); TimeSpan dTime = stopwatch.Elapsed; stopwatch.Restart(); Console.WriteLine("Recursive: " + MWCS_Recurssive(X1, Y1, m, n) + "\n"); stopwatch.Stop(); TimeSpan rTime = stopwatch.Elapsed; Console.WriteLine("Recursive vs. Dynamic Time"); Console.WriteLine("Recursive: " + rTime); Console.WriteLine("Dynamic: " + dTime); Console.WriteLine("\nUzduotis nr. 2\n"); int[] priceArray = new int[] { 1, 5, 8, 9, 10, 17, 17, 20 }; (int, string)rez = CutRod(priceArray, priceArray.Length); Console.WriteLine("Didziausias pelnas: " + rez.Item1); Console.WriteLine("\nUzduotis nr. 3\n"); X1 = Data.GenRandomArray(10000); Y1 = Data.GenRandomArray(10000); m = X1.Length; n = Y1.Length; stopwatch.Restart(); W = MWCS_BottomUp(X1, Y1); Console.WriteLine("Dynamic: " + W[m, n]); stopwatch.Stop(); dTime = stopwatch.Elapsed; stopwatch.Restart(); Console.WriteLine("Parallel: " + MWCS_Parallel(X1, Y1, W) + "\n"); stopwatch.Stop(); TimeSpan pTime = stopwatch.Elapsed; Console.WriteLine("Dynamic vs. Parallel dynamic Time"); Console.WriteLine("Dynamic: " + dTime); Console.WriteLine("Parallel: " + pTime + "\n"); }