コード例 #1
0
        public void TransformTo(C5DataStructure dataStructure)
        {
            if (CurrentDataStructure != dataStructure)
            {
                //Method 1: use case state ment to appropriately copy data over to appropriate data structure
                switch (dataStructure)
                {
                case C5DataStructure.ArrayList:
                    InternalC5DataStructure = CopyToArrayList(InternalC5DataStructure);
                    break;

                case C5DataStructure.LinkedList:
                    InternalC5DataStructure = CopyToLinkedList(InternalC5DataStructure);
                    break;

                case C5DataStructure.HashBag:
                    InternalC5DataStructure = CopyToHashBag(InternalC5DataStructure);
                    break;

                case C5DataStructure.TreeBag:
                    InternalC5DataStructure = CopyToTreeBag(InternalC5DataStructure);
                    break;

                case C5DataStructure.HashedArrayList:
                    InternalC5DataStructure = CopyToHashedArrayList(InternalC5DataStructure);
                    break;

                case C5DataStructure.HashedLinkedList:
                    InternalC5DataStructure = CopyToHashedLinkedList(InternalC5DataStructure);
                    break;

                case C5DataStructure.SortedArray:
                    InternalC5DataStructure = CopyToSortedArray(InternalC5DataStructure);
                    break;

                case C5DataStructure.HashSet:
                    InternalC5DataStructure = CopyToHashSet(InternalC5DataStructure);
                    break;

                case C5DataStructure.TreeSet:
                    InternalC5DataStructure = CopyToTreeSet(InternalC5DataStructure);
                    break;

                default: throw new ArgumentException("Unknown C5 Collection name");
                }

                CurrentDataStructure = dataStructure;
                OnTransformCompleted(EventArgs.Empty);
            }
        }
コード例 #2
0
        public override void CreateNewInstanceOfInternalC5DataStructure(C5DataStructure dataStructure)
        {
            switch (dataStructure)
            {
            case C5DataStructure.ArrayList:
                InternalC5DataStructure = new ArrayList <T>();
                break;

            case C5DataStructure.LinkedList:
                InternalC5DataStructure = new LinkedList <T>();
                break;

            case C5DataStructure.HashBag:
                InternalC5DataStructure = new HashBag <T>();
                break;

            case C5DataStructure.TreeBag:
                InternalC5DataStructure = new TreeBag <T>();
                break;

            case C5DataStructure.HashedArrayList:
                InternalC5DataStructure = new HashedArrayList <T>();
                break;

            case C5DataStructure.HashedLinkedList:
                InternalC5DataStructure = new HashedLinkedList <T>();
                break;

            case C5DataStructure.SortedArray:
                InternalC5DataStructure = new SortedArray <T>();
                break;

            case C5DataStructure.HashSet:
                InternalC5DataStructure = new HashSet <T>();
                break;

            case C5DataStructure.TreeSet:
                InternalC5DataStructure = new TreeSet <T>();
                break;

            default: throw new ArgumentException("Unknown C5 Collection name");
            }
        }
コード例 #3
0
        private void SetDefaultDataStructure(DataStructureGroup interfaceAndSetBagProp)
        {
            C5DataStructure previousDS = base.CurrentDataStructure;

            //this default setting is based on our prior research experiment
            //please read our paper, "Predicting Data Structures for Energy Efficient Computing"
            if (interfaceAndSetBagProp == DataStructureGroup.ICollection)
            {
                base.CurrentDataStructure = C5DataStructure.HashSet;
            }
            else if (interfaceAndSetBagProp == DataStructureGroup.ICollectionBag)
            {
                base.CurrentDataStructure = C5DataStructure.HashBag;
            }
            else if (interfaceAndSetBagProp == DataStructureGroup.ICollectionSet)
            {
                base.CurrentDataStructure = C5DataStructure.HashSet;
            }
            else if (interfaceAndSetBagProp == DataStructureGroup.IList)
            {
                base.CurrentDataStructure = C5DataStructure.HashedLinkedList;
            }
            else if (interfaceAndSetBagProp == DataStructureGroup.IListBag)
            {
                base.CurrentDataStructure = C5DataStructure.ArrayList;
            }
            else if (interfaceAndSetBagProp == DataStructureGroup.IListSet)
            {
                base.CurrentDataStructure = C5DataStructure.HashedLinkedList;
            }
            else
            {
                base.CurrentDataStructure = C5DataStructure.HashSet;
            }
            //This will make sure that the internal data structure is also changed with the same existing data in it
            if (previousDS != base.CurrentDataStructure)
            {
                base.TransformTo(base.CurrentDataStructure);
            }
        }
コード例 #4
0
 public CrudBasedCollection(C5DataStructure dataStructure)
 {
     CurrentDataStructure = dataStructure;
     CreateNewInstanceOfInternalC5DataStructure(dataStructure);
 }
コード例 #5
0
 public abstract void CreateNewInstanceOfInternalC5DataStructure(C5DataStructure dataStructure);
コード例 #6
0
ファイル: Program.cs プロジェクト: michanaj/DUGreen-Project
        static bool _TrainingMode = true;//false;//

        static void Main(string[] args)
        {
            //This is the start of all overhead and consider them as the based system
            //Start the time clock
            // Create new stopwatch
            Stopwatch stopwatch = new Stopwatch();

            ////Create a WattsUp object
            //WattsUp _MyWattsUp = new WattsUp();
            _MyWattsUp.InternalSamplingRate = 1;
            _MyWattsUp.SamplingRate         = 1;
            _MyWattsUp.IsUseWattsDelta      = true;
            _MyWattsUp.OnWuReading         += new WuReadingEventHandler(myWattsUp_OnWuReading);
            //_MyWattsUp.Start(out err);
            StartWattsUpAsynch();

            Console.WriteLine("Sleep..10 sec.");
            System.Threading.Thread.Sleep(10000);
            //Get based power in watts and warm up
            basePowerFlag = 1;

            double basedPower = totalBasePower / Double.Parse(basedPowerReadingCount.ToString());

            Console.WriteLine("BASED Power:" + basedPower);

            //reset the count
            countWattUpReading = 0;
            //warm up
            Console.WriteLine("Warming up....");
            CBC.CrudBasedCollection <string> ds = new CrudBasedCollection <string>();
            for (int i = 0; i < 10000; i++)
            {
                ds.Create("Test");
            }
            while (true)
            {
                if (countWattUpReading >= 10)
                {
                    ds.Clear();
                    break;
                }
            }

            //Create a file
            string fileName = "MyTestResult.csv";

            //Delete if exist
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            //Create
            StreamWriter CsvfileWriter = new StreamWriter(fileName, true);

            //List of all C5 data structures
            C5DataStructure[] c5DSs = new C5DataStructure[] { C5DataStructure.ArrayList, C5DataStructure.HashBag, C5DataStructure.HashedArrayList,
                                                              C5DataStructure.HashedLinkedList, C5DataStructure.HashSet,
                                                              C5DataStructure.LinkedList, C5DataStructure.SortedArray, C5DataStructure.TreeBag, C5DataStructure.TreeSet, }; //9 data structures
            //start element size for training set
            int[] elmSizes =                                                                                                                                                //new int[] { 0, 100, 1000, 10000, 100000}; //option 1: 5 possibilities
                             new int[] {
                0, 50, 100, 500, 1000, 5000, 10000,
                50000
            };                  //option 2: 8 possibilities

            int[] moreElmSize = new int[] { 15000, 20000, 25000, 30000, 35000, 40000, 45000 };

            int[] moreElmSize2 = new int[] { 20, 40, 60, 80, 150, 200, 300, 400, 600, 700, 800, 900 };


            //all possibilities of all proportions of CRUD operations
            //for actual dataset, 80% for learning and 20% for testing
            int[,] crudDatasetOps = new int[, ] { //All 4 ops
                { 70, 10, 10, 10 },               //4
                { 10, 70, 10, 10 },
                { 10, 10, 70, 10 },
                { 10, 10, 10, 70 },

                { 60, 20, 10, 10 },               //12
                { 60, 10, 20, 10 },
                { 60, 10, 10, 20 },
                { 20, 60, 10, 10 },
                { 20, 10, 60, 10 },
                { 20, 10, 10, 60 },
                { 10, 60, 20, 10 },
                { 10, 60, 10, 20 },
                { 10, 20, 60, 10 },
                { 10, 20, 10, 60 },
                { 10, 10, 60, 20 },
                { 10, 10, 20, 60 },

                { 50, 30, 10, 10 },               //12
                { 50, 10, 30, 10 },
                { 50, 10, 10, 30 },
                { 30, 50, 10, 10 },
                { 30, 10, 50, 10 },
                { 30, 10, 10, 50 },
                { 10, 50, 30, 10 },
                { 10, 50, 10, 30 },
                { 10, 30, 50, 10 },
                { 10, 30, 10, 50 },
                { 10, 10, 50, 30 },
                { 10, 10, 30, 50 },

                { 50, 20, 20, 10 },               //12
                { 50, 20, 10, 20 },
                { 50, 10, 20, 20 },
                { 20, 50, 20, 10 },
                { 20, 50, 10, 20 },
                { 20, 20, 50, 10 },
                { 20, 20, 10, 50 },
                { 20, 10, 50, 20 },
                { 20, 10, 20, 50 },
                { 10, 50, 20, 20 },
                { 10, 20, 50, 20 },
                { 10, 20, 20, 50 },

                { 40, 30, 20, 10 },              //24
                { 40, 30, 10, 20 },
                { 40, 20, 30, 10 },
                { 40, 20, 10, 30 },
                { 40, 10, 20, 30 },
                { 40, 10, 30, 20 },
                { 30, 40, 20, 10 },
                { 30, 40, 10, 20 },
                { 30, 20, 40, 10 },
                { 30, 20, 10, 40 },
                { 30, 10, 40, 20 },
                { 30, 10, 20, 40 },
                { 20, 40, 30, 10 },
                { 20, 40, 10, 30 },
                { 20, 30, 40, 10 },
                { 20, 30, 10, 40 },
                { 20, 10, 40, 30 },
                { 20, 10, 30, 40 },
                { 10, 40, 30, 20 },
                { 10, 40, 20, 30 },
                { 10, 30, 40, 20 },
                { 10, 30, 20, 40 },
                { 10, 20, 40, 30 },
                { 10, 20, 30, 40 },

                { 40, 40, 10, 10 },              //6
                { 40, 10, 40, 10 },
                { 40, 10, 10, 40 },
                { 10, 40, 40, 10 },
                { 10, 40, 10, 40 },
                { 10, 10, 40, 40 },

                { 25, 25, 25, 25 },              //1
                //3 ops
                { 80, 10, 10, 0 },               //12
                { 80, 10, 0, 10 },
                { 80, 0, 10, 10 },
                { 10, 80, 10, 0 },
                { 10, 80, 0, 10 },
                { 10, 10, 80, 0 },
                { 10, 10, 0, 80 },
                { 10, 0, 80, 10 },
                { 10, 0, 10, 80 },
                { 0, 80, 10, 10 },
                { 0, 10, 80, 10 },
                { 0, 10, 10, 80 },

                { 70, 20, 10, 0 },               //24
                { 70, 20, 0, 10 },
                { 70, 10, 20, 0 },
                { 70, 10, 0, 20 },
                { 70, 0, 20, 10 },
                { 70, 0, 10, 20 },
                { 20, 70, 10, 0 },
                { 20, 70, 0, 10 },
                { 20, 10, 70, 0 },
                { 20, 10, 0, 70 },
                { 20, 0, 70, 10 },
                { 20, 0, 10, 70 },
                { 10, 70, 20, 0 },
                { 10, 70, 0, 20 },
                { 10, 20, 70, 0 },
                { 10, 20, 0, 70 },
                { 10, 0, 70, 20 },
                { 10, 0, 20, 70 },
                { 0, 70, 20, 10 },
                { 0, 70, 10, 20 },
                { 0, 20, 70, 10 },
                { 0, 20, 10, 70 },
                { 0, 10, 70, 20 },
                { 0, 10, 20, 70 },

                { 60, 30, 10, 0 },               //24
                { 60, 30, 0, 10 },
                { 60, 10, 30, 0 },
                { 60, 10, 0, 30 },
                { 60, 0, 30, 10 },
                { 60, 0, 10, 30 },
                { 30, 60, 10, 0 },
                { 30, 60, 0, 10 },
                { 30, 10, 60, 0 },
                { 30, 10, 0, 60 },
                { 30, 0, 60, 10 },
                { 30, 0, 10, 60 },
                { 10, 60, 30, 0 },
                { 10, 60, 0, 30 },
                { 10, 30, 60, 0 },
                { 10, 30, 0, 60 },
                { 10, 0, 60, 30 },
                { 10, 0, 30, 60 },
                { 0, 60, 30, 10 },
                { 0, 60, 10, 30 },
                { 0, 30, 60, 10 },
                { 0, 30, 10, 60 },
                { 0, 10, 60, 30 },
                { 0, 10, 30, 10 },

                { 50, 30, 20, 0 },               //24
                { 50, 30, 0, 20 },
                { 50, 20, 30, 0 },
                { 50, 20, 0, 30 },
                { 50, 0, 30, 20 },
                { 50, 0, 20, 30 },
                { 30, 50, 20, 0 },
                { 30, 50, 0, 20 },
                { 30, 20, 50, 0 },
                { 30, 20, 0, 50 },
                { 30, 0, 50, 20 },
                { 30, 0, 20, 50 },
                { 20, 50, 30, 0 },
                { 20, 50, 0, 30 },
                { 20, 30, 50, 0 },
                { 20, 30, 0, 50 },
                { 20, 0, 50, 30 },
                { 20, 0, 30, 50 },
                { 0, 50, 30, 20 },
                { 0, 50, 20, 30 },
                { 0, 30, 50, 20 },
                { 0, 30, 20, 50 },
                { 0, 20, 50, 30 },
                { 0, 20, 30, 50 },

                { 40, 30, 30, 0 },               //12
                { 40, 30, 0, 30 },
                { 40, 0, 30, 30 },
                { 30, 40, 30, 0 },
                { 30, 40, 0, 30 },
                { 30, 30, 40, 0 },
                { 30, 30, 0, 40 },
                { 30, 0, 40, 30 },
                { 30, 0, 30, 40 },
                { 0, 40, 30, 30 },
                { 0, 30, 40, 30 },
                { 0, 30, 30, 40 },

                { 33, 33, 33, 0 },               //4
                { 33, 33, 0, 33 },
                { 33, 0, 33, 33 },
                { 0, 33, 33, 33 },
                //2 ops
                { 90, 10, 0, 0 },                //12
                { 90, 0, 10, 0 },
                { 90, 0, 0, 10 },
                { 10, 90, 0, 0 },
                { 10, 0, 90, 0 },
                { 10, 0, 0, 90 },
                { 0, 90, 10, 0 },
                { 0, 90, 0, 10 },
                { 0, 10, 90, 0 },
                { 0, 10, 0, 90 },
                { 0, 0, 90, 10 },
                { 0, 0, 10, 90 },

                { 80, 20, 0, 0 },               //12
                { 80, 0, 20, 0 },
                { 80, 0, 0, 20 },
                { 20, 80, 0, 0 },
                { 20, 0, 80, 0 },
                { 20, 0, 0, 80 },
                { 0, 80, 20, 0 },
                { 0, 80, 0, 20 },
                { 0, 20, 80, 0 },
                { 0, 20, 0, 80 },
                { 0, 0, 80, 20 },
                { 0, 0, 20, 80 },

                { 70, 30, 0, 0 },               //12
                { 70, 0, 30, 0 },
                { 70, 0, 0, 30 },
                { 30, 70, 0, 0 },
                { 30, 0, 70, 0 },
                { 30, 0, 0, 70 },
                { 0, 70, 30, 0 },
                { 0, 70, 0, 30 },
                { 0, 30, 70, 0 },
                { 0, 30, 0, 70 },
                { 0, 0, 70, 30 },
                { 0, 0, 30, 70 },

                { 60, 40, 0, 0 },               //12
                { 60, 0, 40, 0 },
                { 60, 0, 0, 40 },
                { 40, 60, 0, 0 },
                { 40, 0, 60, 0 },
                { 40, 0, 0, 60 },
                { 0, 60, 40, 0 },
                { 0, 60, 0, 40 },
                { 0, 40, 60, 0 },
                { 0, 40, 0, 60 },
                { 0, 0, 60, 40 },
                { 0, 0, 40, 60 },

                { 50, 50, 0, 0 },               //6
                { 50, 0, 50, 0 },
                { 50, 0, 0, 50 },
                { 0, 50, 50, 0 },
                { 0, 50, 0, 50 },
                { 0, 0, 50, 50 },
                //1 op
                { 100, 0, 0, 0 },               //4
                { 0, 100, 0, 0 },
                { 0, 0, 100, 0 },
                { 0, 0, 0, 100 }
            };

            //Total Possibilities = 4 + 12 + 12 + 12 + 24 + 6 + 1 + 12 + 24 + 24 + 24 + 12 + 4 + 12 + 12 +12 + 12 + 6 + 4 = 229

            //Validate sets
            int[] elmSizesValidateSet = new int[] { 2, 93, 143, 421, 1634, 3521, 8374, 47538 }; //for validate set
            int[,] crudValidateSetAllOps = new int[, ] {
                { 73, 8, 5, 14 },                                                               //2
                { 8, 72, 12, 8 },

                { 62, 22, 13, 3 },               //7
                { 62, 13, 22, 3 },
                { 22, 62, 13, 3 },
                { 22, 3, 62, 13 },
                { 3, 22, 13, 62 },
                { 13, 3, 62, 22 },
                { 3, 13, 22, 62 },

                { 54, 26, 3, 17 },               //7
                { 54, 3, 17, 26 },
                { 26, 17, 54, 3 },
                { 17, 54, 26, 3 },
                { 3, 26, 17, 54 },
                { 17, 3, 54, 26 },
                { 3, 17, 26, 54 },

                { 52, 18, 21, 9 },               //7
                { 52, 9, 18, 21 },
                { 21, 52, 18, 9 },
                { 18, 52, 9, 21 },
                { 21, 18, 9, 52 },
                { 18, 9, 52, 21 },
                { 9, 52, 21, 18 },

                { 43, 27, 21, 9 },              //13
                { 43, 21, 27, 9 },
                { 43, 21, 9, 27 },
                { 43, 9, 27, 21 },
                { 27, 43, 9, 21 },
                { 27, 21, 9, 43 },
                { 27, 9, 21, 43 },
                { 21, 43, 27, 9 },
                { 21, 27, 43, 9 },
                { 21, 9, 43, 27 },
                { 9, 43, 27, 21 },
                { 9, 27, 43, 21 },
                { 9, 21, 43, 27 },

                { 42, 42, 8, 8 },              //6
                { 42, 8, 42, 8 },
                { 42, 8, 8, 42 },
                { 8, 42, 42, 8 },
                { 8, 42, 8, 42 },
                { 8, 8, 42, 42 },

                { 23, 27, 23, 27 },              //4
                { 27, 23, 27, 23 },
                { 23, 23, 27, 27 },
                { 27, 27, 23, 23 },
                //3 ops
                { 81, 9, 10, 0 },               //7
                { 9, 10, 81, 0 },
                { 10, 9, 0, 81 },
                { 9, 0, 10, 81 },
                { 0, 81, 9, 10 },
                { 0, 10, 81, 9 },
                { 0, 9, 10, 81 },

                { 69, 9, 22, 0 },               //12
                { 69, 0, 9, 22 },
                { 22, 69, 0, 9 },
                { 22, 9, 69, 0 },
                { 22, 0, 69, 9 },
                { 9, 69, 22, 0 },
                { 9, 22, 69, 0 },
                { 9, 22, 0, 69 },
                { 9, 0, 22, 69 },
                { 0, 69, 9, 22 },
                { 0, 22, 9, 69 },
                { 0, 9, 22, 69 },

                { 59, 0, 12, 29 },               //6
                { 29, 59, 12, 0 },
                { 12, 59, 0, 29 },
                { 12, 0, 59, 29 },
                { 12, 0, 29, 59 },
                { 0, 29, 12, 59 },

                { 49, 19, 32, 0 },               //10
                { 49, 0, 19, 32 },
                { 32, 49, 19, 0 },
                { 32, 49, 0, 19 },
                { 32, 0, 49, 19 },
                { 19, 49, 32, 0 },
                { 19, 32, 49, 0 },
                { 19, 0, 49, 32 },
                { 0, 49, 32, 19 },
                { 0, 32, 49, 19 },

                { 43, 28, 29, 0 },               //10
                { 43, 28, 0, 29 },
                { 28, 43, 29, 0 },
                { 29, 43, 0, 28 },
                { 28, 29, 43, 0 },
                { 29, 28, 0, 43 },
                { 28, 0, 43, 29 },
                { 29, 0, 28, 43 },
                { 0, 43, 28, 29 },
                { 0, 29, 43, 28 },

                { 32, 34, 31, 3 },               //4
                { 34, 32, 3, 31 },
                { 32, 3, 31, 34 },
                { 3, 31, 32, 34 },
                //2 ops
                { 91, 9, 0, 0 },                //12
                { 91, 0, 9, 0 },
                { 91, 0, 0, 9 },
                { 9, 91, 0, 0 },
                { 9, 0, 91, 0 },
                { 9, 0, 0, 91 },
                { 0, 91, 9, 0 },
                { 0, 91, 0, 9 },
                { 0, 9, 91, 0 },
                { 0, 9, 0, 91 },
                { 0, 0, 91, 9 },
                { 0, 0, 9, 91 },

                { 82, 18, 0, 0 },               //12
                { 82, 0, 18, 0 },
                { 82, 0, 0, 18 },
                { 18, 82, 0, 0 },
                { 18, 0, 82, 0 },
                { 18, 0, 0, 82 },
                { 0, 82, 18, 0 },
                { 0, 82, 0, 18 },
                { 0, 18, 82, 0 },
                { 0, 18, 0, 82 },
                { 0, 0, 82, 18 },
                { 0, 0, 18, 82 },

                { 72, 28, 0, 0 },               //12
                { 72, 0, 28, 0 },
                { 72, 0, 0, 28 },
                { 28, 72, 0, 0 },
                { 28, 0, 72, 0 },
                { 28, 0, 0, 72 },
                { 0, 72, 28, 0 },
                { 0, 72, 0, 28 },
                { 0, 28, 72, 0 },
                { 0, 28, 0, 72 },
                { 0, 0, 72, 28 },
                { 0, 0, 28, 72 },

                { 61, 39, 0, 0 },               //12
                { 61, 0, 39, 0 },
                { 61, 0, 0, 39 },
                { 39, 61, 0, 0 },
                { 39, 0, 61, 0 },
                { 39, 0, 0, 61 },
                { 0, 61, 39, 0 },
                { 0, 61, 0, 39 },
                { 0, 39, 61, 0 },
                { 0, 39, 0, 61 },
                { 0, 0, 61, 39 },
                { 0, 0, 39, 61 },

                { 49, 51, 0, 0 },               //6
                { 51, 0, 49, 0 },
                { 51, 0, 0, 49 },
                { 0, 49, 51, 0 },
                { 0, 51, 0, 49 },
                { 0, 0, 49, 51 },
                //1 op
                { 97, 1, 1, 1 },               //5
                { 1, 98, 1, 0 },
                { 1, 0, 99, 0 },
                { 0, 1, 1, 98 },
                { 1, 1, 1, 97 }
            };

            //constant OP lenght and test string object
            int    opLength   = 10000;
            String testString = "TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest";
            int    count      = 1;

            //reset the count
            countWattUpReading = 0;

            //Start
            Console.WriteLine("Start...");
            if (_TrainingMode)
            {
                //ProfileEnergyEnergyDataSet(stopwatch, ref ds, CsvfileWriter, c5DSs, elmSizes, crudDatasetOps, opLength, testString, ref count);
                ProfileEnergyEnergyDataSet(stopwatch, ref ds, CsvfileWriter, c5DSs, moreElmSize2, crudDatasetOps, opLength, testString, ref count);
            }
            else//if create validate set
            {
                ProfileEnergyEnergyDataSet(stopwatch, ref ds, CsvfileWriter, c5DSs, elmSizesValidateSet, crudValidateSetAllOps, opLength, testString, ref count);
            }
            //profile random programs
            //ProfileEnergyEnergyRandomProgram(stopwatch, ref ds, c5DSs, opLength, testString, ref count);

            //profile realworld programs
            //ProfileEnergyEnergyRealWorldProgram(stopwatch, ref ds, c5DSs, opLength, testString, ref count);
            //Cleanup
            CsvfileWriter.Close();
            _MyWattsUp.Stop();
        }