static void Main(string[] args) { string textFile = Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.FullName, "Values.txt"); var watch = new Stopwatch(); string[] lines = File.ReadAllLines(textFile); #region Code for Generation if 1M random Value /* * try * { * using (StreamWriter writer = new StreamWriter(textFile)) * { * for (int i = 1; i <= 100000; i++) * { * Random r = new Random(); * writer.WriteLine(r.Next(10,1000000)); * } * } * } * catch (Exception exp) * { * Console.Write(exp.Message); * }*/ #endregion DynamicIntArray dynamicIntArray = new DynamicIntArray(500000); int[] myArray = new int[100000]; List <int> myList = new List <int>(); ArrayList myArrayList = new ArrayList(); #region DynamicIntArray Analysis Console.WriteLine("Performanace Anaylsis of Custom DynamicIntArray"); watch.Start(); int j = 1; foreach (string line in lines) { Console.WriteLine(j); dynamicIntArray.Add(Convert.ToInt32(line)); j++; } watch.Stop(); Console.WriteLine($"Execution Time for Insertion: {watch.ElapsedMilliseconds} ms"); watch.Restart(); int sum = 0; for (int i = 0; i < dynamicIntArray.curentSize; i++) { sum = sum + dynamicIntArray.Get(i); } watch.Stop(); Console.WriteLine($"Sum of Elements in DynamicIntArray class:- {sum}"); Console.WriteLine($"Execution Time for Traversal: {watch.ElapsedMilliseconds} ms"); watch.Restart(); Console.WriteLine($"Index of 722100:- {dynamicIntArray.indexOf(722100)}"); Console.WriteLine($"Index of 786311:- {dynamicIntArray.indexOf(786311)}"); Console.WriteLine($"Index of 820266:- {dynamicIntArray.indexOf(820266)}"); Console.WriteLine($"Index of 557246:- {dynamicIntArray.indexOf(557246)}"); Console.WriteLine($"Index of 495133:- {dynamicIntArray.indexOf(495133)}"); watch.Stop(); Console.WriteLine($"Execution Time for Searching: {watch.ElapsedMilliseconds} ms"); #endregion #region C# Array Analysis Console.WriteLine("\n\n\nPerformanace Anaylsis of C# Array Datastructure"); watch.Start(); j = 0; foreach (string line in lines) { if (myArray.Length <= j) { Console.WriteLine("Cant Insert more In Array"); break; } else { myArray[j] = (Convert.ToInt32(line)); j++; } } watch.Stop(); Console.WriteLine($"Execution Time for Insertion: {watch.ElapsedMilliseconds} ms"); watch.Restart(); sum = 0; for (int i = 0; i < myArray.Length; i++) { sum = sum + myArray[i]; } watch.Stop(); Console.WriteLine($"Sum of Elements in Array:- {sum}"); Console.WriteLine($"Execution Time for Traversal: {watch.ElapsedMilliseconds} ms"); watch.Restart(); Console.WriteLine($"Index of 722100:- {Array.FindIndex(myArray, item => item == 722100)}"); Console.WriteLine($"Index of 786311:- {Array.FindIndex(myArray, item => item == 786311)}"); Console.WriteLine($"Index of 820266:- {Array.FindIndex(myArray, item => item == 820266)}"); Console.WriteLine($"Index of 557246:- {Array.FindIndex(myArray, item => item == 557246)}"); Console.WriteLine($"Index of 495133:- {Array.FindIndex(myArray, item => item == 495133)}"); watch.Stop(); Console.WriteLine($"Execution Time for Searching: {watch.ElapsedMilliseconds} ms"); #endregion #region Generic List<Int> Analysis //Analysis for List<int> generics Console.WriteLine("\n\n\nPerformanace Anaylsis of System.Generics List<> "); watch.Start(); foreach (string line in lines) { myList.Add(Convert.ToInt32(line)); } watch.Stop(); Console.WriteLine($"Execution Time for Insertion: {watch.ElapsedMilliseconds} ms"); watch.Restart(); sum = 0; for (int i = 0; i < myList.Count; i++) { sum = sum + myList[i]; } watch.Stop(); Console.WriteLine($"Sum of elements in List<>:- {sum}"); Console.WriteLine($"Execution Time for Treversal: {watch.ElapsedMilliseconds} ms"); watch.Restart(); Console.WriteLine($"Index of 722100:- {myList.IndexOf(722100)}"); Console.WriteLine($"Index of 786311:- {myList.IndexOf(786311)}"); Console.WriteLine($"Index of 820266:- {myList.IndexOf(820266)}"); Console.WriteLine($"Index of 557246:- {myList.IndexOf(557246)}"); Console.WriteLine($"Index of 495133:- {myList.IndexOf(495133)}"); watch.Stop(); Console.WriteLine($"Execution Time for Searching: {watch.ElapsedMilliseconds} ms"); #endregion #region System.Collections ArrayList Analysis Console.WriteLine("\n\n\nPerformanace Anaylsis of System.Collection ArrayList"); watch.Start(); foreach (string line in lines) { myArrayList.Add(Convert.ToInt32(line)); } watch.Stop(); Console.WriteLine($"Execution Time for Insertion: {watch.ElapsedMilliseconds} ms"); watch.Restart(); sum = 0; for (int i = 0; i < myArrayList.Count; i++) { sum = sum + (int)myArrayList[i]; } watch.Stop(); Console.WriteLine($"Sum of Elements in ArrayList:- {sum}"); Console.WriteLine($"Execution Time for Treversal: {watch.ElapsedMilliseconds} ms"); watch.Restart(); Console.WriteLine($"Index of 722100:- {myArrayList.IndexOf(722100)}"); Console.WriteLine($"Index of 786311:- {myArrayList.IndexOf(786311)}"); Console.WriteLine($"Index of 820266:- {myArrayList.IndexOf(820266)}"); Console.WriteLine($"Index of 557246:- {myArrayList.IndexOf(557246)}"); Console.WriteLine($"Index of 495133:- {myArrayList.IndexOf(495133)}"); watch.Stop(); Console.WriteLine($"Execution Time for Searching: {watch.ElapsedMilliseconds} ms"); #endregion }