Exemplo n.º 1
0
        /// <summary>
        /// Most of the CRUD operations here is  trying to use upperbound cost operations
        /// Create Last -- add last operation is a default operation restricted by the ICollection interface. Actually, adding/inserting at the first position is considered the highest cost among all add operations
        /// Retrieve Last -- retrieving last item is considered the highest cost among all find operations
        /// Update last -- updating the last item in a collection is considered the highest cost among all update operations
        /// Delete first -- deleting the first item in a collection is considered the highest cost among all delete operations
        /// </summary>
        /// <param name="ds"></param>
        /// <param name="basePopulationSize"></param>
        /// <param name="opLength"></param>
        public static void AllOps(CBC.CrudBasedCollection <string> ds, int basePopulationSize, int opLength, string testString, int cSize, int rSize, int uSize, int dSize)
        {
            string s;
            bool   t;


            //C add cSize times
            for (int i = basePopulationSize; i < basePopulationSize + cSize; i++)
            {
                t = ds.Create(testString + i);
            }

            //R retrieve rSize times
            for (int i = basePopulationSize; i > basePopulationSize - rSize; i--)
            {
                s = ds.Retrieve(testString + i);
            }

            //U update uSize times
            for (int i = basePopulationSize; i > basePopulationSize - uSize; i--)
            {
                t = ds.Update(testString + i);
            }

            //D delete dSize times
            for (int i = basePopulationSize; i > basePopulationSize - dSize; i--)
            {
                t = ds.Delete(testString + i);
            }
        }
Exemplo n.º 2
0
        private static void ProfileEnergyEnergyRandomProgram(Stopwatch stopwatch, ref CBC.CrudBasedCollection <string> ds, C5DataStructure[] c5DSs, int opLength, String testString, ref int count)
        {
            //Run three Runs
            for (int run = 0; run < 3; run++)
            {
                //for each file fo 100 files
                for (int i = 0; i < 100; i++)
                {
                    string applicationRawXValuesFileName = string.Format(@"RandomPrograms\RawXValuesOfRandomApplication{0}.csv", i);
                    //read file
                    //1. Read data from a Dataset
                    List <string[]> rawDatasetArrays = Helpers.parseCSV(applicationRawXValuesFileName);

                    //for writing result
                    string writeFileName = string.Format(@"RandomPrograms\Run I\Result_RawXValuesOfRandomApplication{0}.csv", i);
                    if (run == 1)
                    {
                        writeFileName = string.Format(@"RandomPrograms\Run II\Result_RawXValuesOfRandomApplication{0}.csv", i);
                    }
                    else if (run == 2)
                    {
                        writeFileName = string.Format(@"RandomPrograms\Run III\Result_RawXValuesOfRandomApplication{0}.csv", i);
                    }
                    //Delete if exist
                    if (File.Exists(writeFileName))
                    {
                        File.Delete(writeFileName);
                    }
                    //Create
                    StreamWriter CsvfileWriter = new StreamWriter(writeFileName, true);

                    Console.WriteLine("Start profiling progrm " + applicationRawXValuesFileName + " ...");

                    foreach (var d in rawDatasetArrays)
                    {
                        //for each C5 data structure
                        for (int j = 0; j < c5DSs.Length; j++)
                        {
                            Console.WriteLine("Start " + c5DSs[j].ToString() + " with start element size = " + d[0]);


                            //for each CRUD op proportion
                            //for (int k = 0; k < crudDatasetOps.GetLength(0); k++)
                            //{
                            ds = new CBC.CrudBasedCollection <string>(c5DSs[j]);
                            //calculate number of CRUD operations
                            int    C = (int.Parse(d[1]) * opLength) / 100;
                            int    R = (int.Parse(d[2]) * opLength) / 100;
                            int    U = (int.Parse(d[3]) * opLength) / 100;
                            int    D = (int.Parse(d[4]) * opLength) / 100;
                            int    basePopulationSize = int.Parse(d[0]);
                            double totaltime          = 0.0;
                            int    iterationCount     = 0;
                            totalWatts         = 0.0;
                            countWattUpReading = 0;


                            while (true)//keep doing until the wattsup readings is greater than some threshole
                            {
                                bool t;
                                //Generating based population
                                for (int p = 0; p < basePopulationSize; p++)
                                {
                                    t = ds.Create(testString + p);
                                }


                                //start the clock
                                stopwatch.Restart();

                                //Conducting the operations
                                AllOps(ds, basePopulationSize, opLength, testString, C, R, U, D);

                                //stop the clock
                                stopwatch.Stop();

                                //time in second
                                totaltime = totaltime + (stopwatch.Elapsed.TotalSeconds);
                                iterationCount++;

                                //clear all elements
                                ds.Clear();

                                //check if its time to stop
                                if (countWattUpReading >= 5)
                                {
                                    break;
                                }
                            }

                            double averageTime  = totaltime / iterationCount;
                            double averageWatts = totalWatts / (countWattUpReading - 3);//the first two are ignore because of the delay

                            string result = count + "," + c5DSs[j].ToString() + "," + d[0] + "," + d[1] + "," + d[2] + "," + d[3] + "," + d[4] + " #Iteration:" + iterationCount + " Avg Time(Sec):" + averageTime.ToString() + " Avg Power(Watts): " + averageWatts.ToString() + ", Energy (J):" + (averageTime * averageWatts).ToString();
                            Console.WriteLine("Result:" + result);
                            string savedToFileResult = count + "," + c5DSs[j].ToString() + "," + d[0] + "," + d[1] + "," + d[2] + "," + d[3] + "," + d[4] + "," + averageTime.ToString() + "," + averageWatts.ToString() + "," + (averageTime * averageWatts).ToString();
                            CsvfileWriter.WriteLine(savedToFileResult);

                            //reset the count to zero
                            totalWatts         = 0.0;
                            countWattUpReading = 0;
                            totaltime          = 0.0;
                            count++;

                            //}
                        }
                    }//end for each x-value set

                    CsvfileWriter.Close();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Energy Profiling
        /// </summary>
        /// <param name="stopwatch"></param>
        /// <param name="ds"></param>
        /// <param name="CsvfileWriter"></param>
        /// <param name="c5DSs"></param>
        /// <param name="elmSizes"></param>
        /// <param name="crudDatasetOps"></param>
        /// <param name="opLength"></param>
        /// <param name="testString"></param>
        /// <param name="count"></param>
        private static void ProfileEnergyEnergyDataSet(Stopwatch stopwatch, ref CBC.CrudBasedCollection <string> ds, StreamWriter CsvfileWriter, C5DataStructure[] c5DSs, int[] elmSizes, int[,] crudDatasetOps, int opLength, String testString, ref int count)
        {
            //for each start element size
            for (int i = 0; i < elmSizes.Length; i++)
            {
                //for each C5 data structure
                for (int j = 0; j < c5DSs.Length; j++)
                {
                    Console.WriteLine("Start " + c5DSs[j].ToString() + " with start element size = " + elmSizes[i]);


                    //for each CRUD op proportion
                    for (int k = 0; k < crudDatasetOps.GetLength(0); k++)
                    {
                        ds = new CBC.CrudBasedCollection <string>(c5DSs[j]);
                        //calculate number of CRUD operations
                        int    C = ((crudDatasetOps[k, 0]) * opLength) / 100;
                        int    R = ((crudDatasetOps[k, 1]) * opLength) / 100;
                        int    U = ((crudDatasetOps[k, 2]) * opLength) / 100;
                        int    D = ((crudDatasetOps[k, 3]) * opLength) / 100;
                        int    basePopulationSize = elmSizes[i];
                        double totaltime          = 0.0;
                        int    iterationCount     = 0;
                        totalWatts         = 0.0;
                        countWattUpReading = 0;
                        while (true)//keep doing until the wattsup readings is greater than some threshole
                        {
                            bool t;
                            //Generating based population
                            for (int p = 0; p < basePopulationSize; p++)
                            {
                                t = ds.Create(testString + p);
                            }


                            //start the clock
                            stopwatch.Restart();

                            //Conducting the operations
                            AllOps(ds, basePopulationSize, opLength, testString, C, R, U, D);

                            //stop the clock
                            stopwatch.Stop();

                            //time in second
                            totaltime = totaltime + (stopwatch.Elapsed.TotalSeconds);
                            iterationCount++;

                            //clear all elements
                            ds.Clear();

                            //check if its time to stop
                            if (countWattUpReading >= 5)
                            {
                                break;
                            }
                        }

                        double averageTime  = totaltime / iterationCount;
                        double averageWatts = totalWatts / (countWattUpReading - 3);//the first two are ignore because of the delay

                        string result = count + "," + c5DSs[j].ToString() + "," + elmSizes[i] + "," + crudDatasetOps[k, 0].ToString() + "," + crudDatasetOps[k, 1].ToString() + "," + crudDatasetOps[k, 2].ToString() + "," + crudDatasetOps[k, 3].ToString() + " #Iteration:" + iterationCount + " Avg Time(Sec):" + averageTime.ToString() + " Avg Power(Watts): " + averageWatts.ToString() + ", Energy (J):" + (averageTime * averageWatts).ToString();
                        Console.WriteLine("Result:" + result);
                        string savedToFileResult = count + "," + c5DSs[j].ToString() + "," + elmSizes[i] + "," + crudDatasetOps[k, 0].ToString() + "," + crudDatasetOps[k, 1].ToString() + "," + crudDatasetOps[k, 2].ToString() + "," + crudDatasetOps[k, 3].ToString() + "," + averageTime.ToString() + "," + averageWatts.ToString() + "," + (averageTime * averageWatts).ToString();
                        CsvfileWriter.WriteLine(savedToFileResult);

                        //reset the count to zero
                        totalWatts         = 0.0;
                        countWattUpReading = 0;
                        totaltime          = 0.0;
                        count++;
                    }
                }
            }
        }