// Insert in middle of structure test public TestModel MidInsertTest(int newIterations, string structureName) { ReadFiles(); long memStart = 0, memEnd = 0; for (int i = 1; i < newIterations + 1; i++) { // get pre-fill memory memStart = GC.GetTotalMemory(true); switch (structureName) { case "StringBuilder": newTestModel.title = "StringBuilder"; newTestModel.method = ($"Insert a copy of War and Peace into middle of data structure; repeat {newIterations} times"); builderLarge = new StringBuilder(); sw.Start(); builderLarge.Insert(builderLarge.Length / 2, stringLong); sw.Stop(); break; case "BigList": newTestModel.title = "BigList"; newTestModel.method = ($"Insert a copy of War and Peace into middle of data structure; repeat {newIterations} times"); biglistLarge = new BigList <string>(); sw.Start(); biglistLarge.Insert(biglistLarge.Count / 2, stringLong); sw.Stop(); break; case "Rope": newTestModel.title = "Rope"; newTestModel.method = ($"Insert a copy of War and Peace into middle of data structure; repeat {newIterations} times"); ropeLarge = new Rope.Rope <string>(); sw.Start(); ropeLarge.AddRange(newArray, ropeLarge.Length / 2, newArray.Length); sw.Stop(); break; } memEnd = GC.GetTotalMemory(false); TestDataModel newTestData = new TestDataModel { id = i, memory = (memEnd - memStart), time = sw.ElapsedTicks }; // Gets sum of time and memory averageTime += newTestData.time; averageMemory += newTestData.memory; newTestDataModel.Add(newTestData); sw.Reset(); } newTestModel.averageTime = averageTime / newIterations; newTestModel.averageMemory = averageMemory / newIterations; newTestModel.data = newTestDataModel; return(newTestModel); }
// Method to Concatenate Ropes. public void RopeConcatTestCreateRopes() { // Lists to calculate averages. See if you can declare these once and reset? /* * List<int> lengths = new List<int>(); * List<double> memallocs = new List<double>(); * List<double> runtimes = new List<double>(); */ // Metadata information. structureName = "Rope"; for (int i = 0; i < fNumReplications; i++) { for (int j = 0; j < fNumIterations; j++) { TestDataModel newTestData = new TestDataModel(); // Get memory pre-operation. memStart = GC.GetTotalMemory(true); //Start stopwatch. sw.Reset(); sw.Start(); // These should be faster than converting to charArray, //and then you can just read the file in the very beginning //and not count that in the time & memory! Rope.Rope <string> ropeWarPeace = new Rope.Rope <string> (warPeace.Split(" ".ToCharArray())); //splits on word, can split on sentence too. Might need to go back to char arrays for consistency. Rope.Rope <string> ropeFoxSentence = new Rope.Rope <string> (foxSentence.Split(" ".ToCharArray())); Console.WriteLine(ropeFoxSentence); // Concatenate Ropes. // This is shorter than the others now since it's splitting on words... Rope.Rope <string> ropeConcat = Rope.Rope <string> .Concat(ropeWarPeace, ropeFoxSentence); // Stop timer. sw.Stop(); // Get Memory after operation. memEnd = GC.GetTotalMemory(false); Console.WriteLine("Start {0} End {1}", memStart, memEnd); //Calculate total memory. memUsed = memEnd - memStart; //Console.WriteLine(memUsed); // Append values to each list. //lengths.Add(ropeConcat.Length); //memallocs.Add(memUsed); // runtimes.Add(sw.ElapsedTicks); } // Print averages of ropeConcat.Length, Runtime, for each rep and export to JSON // Print time will need to be JSON EXPORT! /* * Console.WriteLine("Length of new rope: " + lengths.Sum() / lengths.Count() + " words" + * "\nRuntime: " + runtimes.Sum() / lengths.Count() + " ms" + * "\nMemory used: " + memallocs.Sum() / memallocs.Count() + " bytes");*/ } }
public void PrependToLargeStructures(int replications, int iterations) { // timer variables Stopwatch sw = new Stopwatch(); double builderFill = 0; double biglistFill = 0; double ropeFill = 0; // memory variables double memStart = 0; double memEnd = 0; double builderMem = 0; double biglistMem = 0; double ropeMem = 0; // create an enumerable structure of the long string as feed for rope newArray = stringLong.ToCharArray(); // Call the fill service to create large structures FillService insertFillService = new FillService(); insertFillService.ReadFiles(); insertFillService.FillLargeStructures(iterations); StringBuilder builderLarge = insertFillService.builderLarge; BigList <char> biglistLarge = insertFillService.biglistLarge; Rope.Rope <char> ropeLarge = insertFillService.ropeLarge; // time insertion of string into structures with a single copy of war and peace // --------------------------------------------------------------- // metadata information titleStructure = "StringBuilder"; // fill stringbuilder for (int i = 0; i < replications; i++) { // get pre-fill memory memStart = GC.GetTotalMemory(false); // start timer sw.Start(); builderLarge.Insert(0, stringLong); sw.Stop(); memEnd = GC.GetTotalMemory(false); builderMem = memEnd - memStart; builderFill = sw.ElapsedMilliseconds; // Manual json build Test dataExport = new Test(replications, titleStructure, titleMethod, "teststringofmethodology", i, builderFill, builderMem); json = dataExport.CreateJson(dataExport); if (jsonLinesSB == "") { jsonLinesSB = json; } else { jsonLinesSB = jsonLinesSB + ", " + json; } } // metadata information titleStructure = "BigList"; // fill biglist for (int i = 0; i < replications; i++) { // get pre-fill memory memStart = GC.GetTotalMemory(false); // start timer sw.Start(); foreach (char letter in newArray) { biglistLarge.Insert(0, letter); } sw.Stop(); memEnd = GC.GetTotalMemory(false); biglistMem = memEnd - memStart; biglistFill = sw.ElapsedMilliseconds; // Manual json build Test dataExport = new Test(replications, titleStructure, titleMethod, "teststringofmethodology", i, builderFill, builderMem); json = dataExport.CreateJson(dataExport); if (jsonLinesBL == "") { jsonLinesBL = json; } else { jsonLinesBL = jsonLinesBL + ", " + json; } } // metadata information titleStructure = "Rope"; // insert into rope for (int i = 0; i < replications; i++) { memStart = GC.GetTotalMemory(false); sw.Start(); ropeLarge.AddRange(newArray, 0, newArray.Length); sw.Stop(); memEnd = GC.GetTotalMemory(false); ropeMem = memEnd - memStart; ropeFill = sw.ElapsedMilliseconds; //Manual json build Test dataExport = new Test(replications, titleStructure, titleMethod, "teststringofmethodology", i, builderFill, builderMem); json = dataExport.CreateJson(dataExport); if (jsonLinesR == "") { jsonLinesR = json; } else { jsonLinesR = jsonLinesR + ", " + json; } } // append brackets jsonLinesR = "[" + jsonLinesR + "]"; jsonLinesSB = "[" + jsonLinesSB + "]"; jsonLinesBL = "[" + jsonLinesBL + "]"; // write to files using (StreamWriter writeResults = new StreamWriter(@"c:\repos\files\InsertResultsSB.txt")) { writeResults.WriteLine(jsonLinesSB); } using (StreamWriter writeResults = new StreamWriter(@"c:\repos\files\InsertResultsBL.txt")) { writeResults.WriteLine(jsonLinesBL); } using (StreamWriter writeResults = new StreamWriter(@"c:\repos\files\InsertResultsR.txt")) { writeResults.WriteLine(jsonLinesR); } }
public TestModel AppendTest(int newIterations, string structureName) { // Function that read in the file(s) to test. ReadFiles(); // Initialize variables that will store memory at 0. long memStart = 0; long memEnd = 0; // Appends a file to the specified data structure i number of times. for (int i = 1; i < newIterations + 1; i++) { // Get pre-operation memory. memStart = GC.GetTotalMemory(true); switch (structureName) { // Appends a rope repeatedly to another rope. case "Rope": newTestModel.title = "Rope"; newTestModel.method = ($"Append a copy of War and Peace to the end of the data structure; repeat {newIterations} times"); ropeLarge = new Rope.Rope <string>(); sw.Start(); ropeLarge.AddRange(newArray, ropeLarge.Length, newArray.Length); sw.Stop(); break; // Appends a string repeatedly to a stringbuilder. case "StringBuilder": newTestModel.title = "StringBuilder"; newTestModel.method = ($"Append a copy of War and Peace to the end of the data structure; repeat {newIterations} times"); builderLarge = new StringBuilder(); sw.Start(); builderLarge.Append(stringLong); sw.Stop(); break; case "BigList": newTestModel.title = "BigList"; newTestModel.method = ($"Append a copy of War and Peace to the end of the data structure; repeat {newIterations} times"); biglistLarge = new BigList <string>(); sw.Start(); //foreach (string letter in newArray) Don't understanf why foreach loop is here... //{ biglistLarge.Add(stringLong); //} sw.Stop(); break; } //Get Memory post operations. memEnd = GC.GetTotalMemory(false); TestDataModel newTestData = new TestDataModel { id = i, memory = (memEnd - memStart), time = sw.ElapsedTicks }; // Gets sum of time and memory averageTime += newTestData.time; averageMemory += newTestData.memory; newTestDataModel.Add(newTestData); sw.Reset(); } newTestModel.averageTime = averageTime / newIterations; newTestModel.averageMemory = averageMemory / newIterations; newTestModel.data = newTestDataModel; return(newTestModel); }
public void FillLargeStructures(int newIterations) { iterations = newIterations; // timer variables Stopwatch sw = new Stopwatch(); double builderFill = 0; double biglistFill = 0; double ropeFill = 0; // memory variables double memStart = 0; double memEnd = 0; double builderMem = 0; double biglistMem = 0; double ropeMem = 0; // create an enumerable structure of the long string newArray = stringLong.ToCharArray(); // time filling of data structures with a single instance of string // --------------------------------------------------------------- // metadata information titleStructure = "StringBuilder"; // fill stringbuilder for (int i = 1; i < iterations + 1; i++) { // get pre-fill memory memStart = GC.GetTotalMemory(false); // start timer sw.Start(); builderLarge = new StringBuilder(stringLong); sw.Stop(); memEnd = GC.GetTotalMemory(false); builderMem = memEnd - memStart; builderFill = sw.ElapsedMilliseconds; averageSB += averageSB; // Manual json build Test dataExport = new Test(replications, titleStructure, titleMethod, "teststringofmethodology", i, builderFill, builderMem); json = dataExport.CreateJson(dataExport); // new data structure test //Data newDataExport = new RopeTest.Data(i, builderFill, builderMem); //Test newTestExport = new RopeTest.Test(replications, titleStructure, titleMethod, newDataExport); if (jsonLinesSB == "") { jsonLinesSB = json; } else { jsonLinesSB = jsonLinesSB + ", " + json; } } // metadata information titleStructure = "BigList"; // fill biglist for (int i = 1; i < (int)iterations + 1; i++) { // get pre-fill memory memStart = GC.GetTotalMemory(false); // start timer sw.Start(); biglistLarge = new BigList <char>(newArray); sw.Stop(); memEnd = GC.GetTotalMemory(false); biglistMem = memEnd - memStart; biglistFill = sw.ElapsedMilliseconds; averageBL += averageBL; // Manual json build Test dataExport = new Test(replications, titleStructure, titleMethod, "teststringofmethodology", i, builderFill, builderMem); json = dataExport.CreateJson(dataExport); // new data structure test //Data newDataExport = new RopeTest.Data(i, builderFill, builderMem); //Test newTestExport = new RopeTest.Test(replications, titleStructure, titleMethod, newDataExport); if (jsonLinesBL == "") { jsonLinesBL = json; } else { jsonLinesBL = jsonLinesBL + ", " + json; } } // metadata information titleStructure = "Rope"; // fill rope for (int i = 1; i < (int)iterations + 1; i++) { memStart = GC.GetTotalMemory(false); sw.Start(); ropeLarge = new Rope.Rope <char>(newArray, 0, newArray.Length); sw.Stop(); memEnd = GC.GetTotalMemory(false); ropeMem = memEnd - memStart; ropeFill = sw.ElapsedMilliseconds; averageR += averageR; //Manual json build Test dataExport = new Test(replications, titleStructure, titleMethod, "teststringofmethodology", i, builderFill, builderMem); json = dataExport.CreateJson(dataExport); // new data structure test //Data newDataExport = new RopeTest.Data(i, builderFill, builderMem); //Test newTestExport = new RopeTest.Test(replications, titleStructure, titleMethod, newDataExport); if (jsonLinesR == "") { jsonLinesR = json; } else { jsonLinesR = jsonLinesR + ", " + json; } } // append brackets jsonLinesR = "[" + jsonLinesR + "]"; jsonLinesSB = "[" + jsonLinesSB + "]"; jsonLinesBL = "[" + jsonLinesBL + "]"; // write to files using (StreamWriter writeResults = new StreamWriter(@"c:\repos\files\FillResultsSB.txt")) { writeResults.WriteLine(jsonLinesSB); } using (StreamWriter writeResults = new StreamWriter(@"c:\repos\files\FillResultsBL.txt")) { writeResults.WriteLine(jsonLinesBL); } using (StreamWriter writeResults = new StreamWriter(@"c:\repos\files\FillResultsR.txt")) { writeResults.WriteLine(jsonLinesR); } }