示例#1
0
        // 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);
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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);
        }