예제 #1
0
        public static void Run()
        {
            PrecisionTimer   timer = new PrecisionTimer();
            PagedArray <int> paged = new PagedArray <int>(2, 64);

            int[] normy = new int[2048];

            normy[0]  = 1;
            normy[15] = 1;
            paged[0]  = 1;
            paged[15] = 1;
            for (int i = 0; i < 1; i++)
            {
                timer.Reset();
                timer.Start();
                Array.Copy(normy, 0, normy, 34, 16);
                timer.Stop();
            }

            Console.WriteLine(timer.ElapsedSecondsF);

            paged[50] = 0;

            for (int i = 0; i < 1; i++)
            {
                timer.Reset();

                timer.Start();
                paged.CopyData(0, 16, 34);
                timer.Stop();
            }

            Console.WriteLine(timer.ElapsedSecondsF);

            Console.ReadLine();
        }
예제 #2
0
        public static void Run()
        {
            PrecisionTimer timer = new PrecisionTimer();
            //CompleteBinarySearchTree<int> test = new CompleteBinarySearchTree<int>(10, 1);

            int count = 16384;

            //timer.Start();
            //for (int i = 0; i < count; i++)
            //        test.Add(i, i);
            //timer.Stop();



            double time = timer.ElapsedSeconds / count;

            int[]            testArray = new int[count];
            PagedArray <int> testPaged = new PagedArray <int>(14, 1);

            testPaged[int.MaxValue] = 1;
            int a = 0;
            IEnumerator <int> enumer = testPaged.GetEnumerator();

            timer.Reset();
            //Console.ReadLine();
            timer.Start();
            while (enumer.MoveNext())
            //foreach (int i in testArray)
            {
                //timer.Stop();
                //Console.WriteLine(i);
                //timer.Start();
                a = enumer.Current;
                //a = i;
            }
            timer.Stop();
            //Console.WriteLine(a);

            //Console.WriteLine(time);
            //Console.WriteLine(time * count);
            //Console.WriteLine(time / (1.0 / 60.0) * 100);
            Console.WriteLine(timer.ElapsedSeconds / count);
            Console.WriteLine(timer.ElapsedSeconds);
            Console.WriteLine(timer.ElapsedSeconds / (1.0 / 60.0) * 100);
            Console.WriteLine(1.0 / 60.0);
            Console.ReadLine();
        }
예제 #3
0
        public static void Run()
        {
            PrecisionTimer timer = new PrecisionTimer();
            Random         rand = new Random();
            int            a, b, c = 0;

            timer.Start();
            for (int i = 0; i < 100000; i++)
            {
                a = rand.Next();
                b = rand.Next();
                if (a > b)
                {
                    c = a;
                    b = c;
                }
                else
                {
                    c = b;
                    b = a;
                }
            }
            timer.Stop();

            Console.WriteLine(c);
            Console.WriteLine(timer.ElapsedSeconds);

            timer.Reset();
            timer.Start();
            for (int i = 0; i < 100000; i++)
            {
                a = rand.Next();
                b = rand.Next();
                c = a > b ? a : b;
                b = a > b ? c : a;
            }
            timer.Stop();

            Console.WriteLine(c);
            Console.WriteLine(timer.ElapsedSeconds);

            Console.ReadLine();
        }
예제 #4
0
        public static void Run()
        {
            int threadCount = Environment.ProcessorCount;

            Thread[] threads = new Thread[threadCount];
            Primes  = new long[threadCount];
            barrier = new Barrier(threadCount);

            threads[0] = Thread.CurrentThread;

            PrecisionTimer timer = new PrecisionTimer();

            for (int i = 1; i < threadCount; i++)
            {
                threads[i] = new Thread(ThreadMethodBarrier);
            }

            timer.Reset();
            timer.Start();
            for (int j = 1; j < threadCount; j++)
            {
                threads[j].Start(j);
            }
            for (int i = 0; i < 1000; i++)
            {
                Primes[0] = FindPrimeNumber(10000);
                barrier.SignalAndWait();
            }
            Running = false;
            timer.Stop();
            Console.WriteLine("Barrier Time: " + (timer.ElapsedSecondsF / 1000));
            Console.WriteLine("Primes Found");
            for (int i = 0; i < threadCount; i++)
            {
                Console.WriteLine(Primes[i]);
            }
            Console.ReadLine();
        }
예제 #5
0
        public static void Run(int entityCount, int componentCount)
        {
            PrecisionTimer timer = new PrecisionTimer();

            List <int>[] componentLists     = new List <int> [componentCount];
            int[]        requiredComponents = new int[componentCount];
            Random       rand = new Random();

            for (int i = 0; i < componentCount; i++)
            {
                componentLists[i]     = new List <int>(entityCount);
                requiredComponents[i] = i;
            }

            for (int i = 0; i < entityCount; i++)
            {
                for (int j = 0; j < componentCount; j++)
                {
                    if (rand.Next(10) > 5)
                    {
                        componentLists[j].Add(i);
                    }
                }
            }

            Console.WriteLine("Time to Create Entity : " + timer.ElapsedSeconds);

            timer.Reset();

            List <int[]> components = new List <int[]>();

            timer.Reset();

            timer.Start();
            int[] place = new int[requiredComponents.Length];
            bool  done  = false;

            for (place[0] = 0; place[0] < componentLists[0].Count; place[0]++)
            {
                int count = 1;
                int val   = componentLists[0][place[0]];
                for (int i = 1; i < place.Length; i++)
                {
                    while (componentLists[i][place[i]] < val)
                    {
                        place[i]++;
                        if (place[i] == componentLists[i].Count)
                        {
                            done = true;
                            break;
                        }
                    }

                    if (done)
                    {
                        break;
                    }

                    if (componentLists[i][place[i]] > val)
                    {
                        break;
                    }
                    count++;
                }

                if (done)
                {
                    break;
                }

                if (count == place.Length)
                {
                    components.Add(place);
                }
            }

            timer.Stop();


            Console.WriteLine("Time for Component Worst Case: " + timer.ElapsedSeconds);
            Console.ReadLine();
        }
예제 #6
0
        public static void Run()
        {
            PrecisionTimer timer = new PrecisionTimer();
            Random         rand  = new Random();

            int[] ID1 = new int[100000];
            int[] ID2 = new int[1000];

            Console.WriteLine("Set Equivalence Test");

            for (int i = 0; i < ID1.Length; i++)
            {
                ID1[i] = rand.Next();
                if (i < ID2.Length)
                {
                    ID2[i] = ID1[i];
                }
            }

            bool found = false;

            timer.Start();
            for (int i = 0; i < ID1.Length; i++)
            {
                found = false;
                for (int j = 0; j < ID2.Length; j++)
                {
                    if (ID1[i] == ID2[j])
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    break;
                }
            }
            timer.Stop();

            Console.WriteLine(found);
            Console.WriteLine(timer.ElapsedSeconds);
            timer.Reset();

            timer.Start();
            found = ID1.All((i) => { return(ID2.Contains(i)); });
            timer.Stop();

            Console.WriteLine(found);
            Console.WriteLine(timer.ElapsedSeconds);
            timer.Reset();

            timer.Start();
            found = ID1.All((i) => { return(ID2.Any((j) => { return i == j; })); });
            timer.Stop();

            Console.WriteLine(found);
            Console.WriteLine(timer.ElapsedSeconds);
            timer.Reset();

            timer.Start();
            //Fastest in worst case
            found = !ID1.Any((i) => { return(!ID2.Contains(i)); });
            timer.Stop();

            Console.WriteLine(found);
            Console.WriteLine(timer.ElapsedSeconds);
            timer.Reset();

            for (int i = 0; i < ID2.Length; i++)
            {
                ID2[i] = rand.Next();
            }

            timer.Start();
            //fastest in best case
            for (int i = 0; i < ID1.Length; i++)
            {
                found = false;
                for (int j = 0; j < ID2.Length; j++)
                {
                    if (ID1[i] == ID2[j])
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    break;
                }
            }
            timer.Stop();

            Console.WriteLine(found);
            Console.WriteLine(timer.ElapsedSeconds);
            timer.Reset();

            timer.Start();
            found = ID1.All((i) => { return(ID2.Contains(i)); });
            timer.Stop();

            double temp = timer.ElapsedSeconds;

            Console.WriteLine(found);
            Console.WriteLine(timer.ElapsedSeconds);
            timer.Reset();

            timer.Start();
            found = ID1.All((i) => { return(ID2.Any((j) => { return i == j; })); });
            timer.Stop();

            Console.WriteLine(found);
            Console.WriteLine(timer.ElapsedSeconds);
            timer.Reset();

            //
            //
            // Best in Worst Case and Close 2nd in Best Case
            //
            //
            timer.Start();
            found = !ID1.Any((i) => { return(!ID2.Contains(i)); });
            timer.Stop();

            Console.WriteLine(found);
            Console.WriteLine(timer.ElapsedSeconds);
            Console.WriteLine(timer.ElapsedSeconds / temp * 100);
            timer.Reset();

            Console.ReadLine();
        }
예제 #7
0
        void Run(SystemInfo[] systems, SystemType type, double time, int laneCount)
        {
            int            typeCount    = 0;
            double         averageTime  = 0;
            PrecisionTimer processTimer = new PrecisionTimer();
            PrecisionTimer unitTimer    = new PrecisionTimer();

            Console.WriteLine("Test 1 - Adding All Systems at Once");

            for (int i = 0; i < systems.Length; i++)
            {
                if (systems[i].Type == type)
                {
                    typeCount++;
                }
            }

            SafeSystemSchedule schedule = new SafeSystemSchedule(SystemType.Logic, laneCount, typeCount);

            processTimer.Start();
            for (int i = 0; i < systems.Length; i++)
            {
                unitTimer.Start();
                SystemInfo sysInf = systems[i];
                if (!sysInf.Active || sysInf.Type != type)
                {
                    unitTimer.Stop();
                    averageTime = MathHelper.MovingAverage(averageTime, unitTimer.ElapsedSeconds, i + 1);
                    unitTimer.Reset();
                    continue;
                }
                schedule.Add(sysInf);
                unitTimer.Stop();
                processTimer.Stop();
                averageTime = MathHelper.MovingAverage(averageTime, unitTimer.ElapsedSeconds, i + 1);
                unitTimer.Reset();
                processTimer.Start();
            }
            processTimer.Stop();

            Console.WriteLine("Total Time to Register : " + processTimer.ElapsedSeconds);
            Console.WriteLine("Average Time to Register : " + averageTime);
            Console.WriteLine("Extrapolated Time to Register : " + (averageTime * systems.Length));
            Console.WriteLine("Extrapolated Time without nonTypes : " + (averageTime * typeCount));
            processTimer.Reset();

            Console.ReadLine();

            Console.WriteLine("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
            Console.WriteLine("Test 2 - Adding Each System One at a Time");

            averageTime = 0;
            schedule.Clear();
            processTimer.Start();
            for (int i = 0; i < systems.Length; i++)
            {
                unitTimer.Start();
                SystemInfo sysInf = systems[i];
                if (!sysInf.Active || sysInf.Type != type)
                {
                    unitTimer.Stop();
                    averageTime = MathHelper.MovingAverage(averageTime, unitTimer.ElapsedSeconds, i + 1);
                    unitTimer.Reset();
                    continue;
                }
                schedule.Add(sysInf);
                unitTimer.Stop();
                processTimer.Stop();
                averageTime = MathHelper.MovingAverage(averageTime, unitTimer.ElapsedSeconds, i + 1);
                unitTimer.Reset();

                while (schedule.NextSystem(0, out SystemInfo sysInfo) != ScheduleResult.Finished)
                {
                    sysInfo.Age = 1;
                }

                processTimer.Start();
            }
            processTimer.Stop();

            Console.WriteLine("Total Time to Register : " + processTimer.ElapsedSeconds);
            Console.WriteLine("Average Time to Register : " + averageTime);
            Console.WriteLine("Extrapolated Time to Register : " + (averageTime * systems.Length));
            Console.WriteLine("Extrapolated Time without nonTypes : " + (averageTime * typeCount));
            processTimer.Reset();

            Console.ReadLine();

            Console.WriteLine("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
            Console.WriteLine("Test 3 - Clear List and Readd");

            SafeSystemSchedule copy = new SafeSystemSchedule(schedule);

            foreach (SystemInfo sysinf in systems)
            {
                SystemUpdate(sysinf);
            }

            processTimer.Start();
            schedule.Clear();

            for (int i = 0; i < systems.Length; i++)
            {
                SystemInfo sysInf = systems[i];
                if (!sysInf.Active || sysInf.Type != type)
                {
                    continue;
                }
                schedule.Add(sysInf);
            }
            processTimer.Stop();

            while (schedule.NextSystem(0, out SystemInfo sysInfo) != ScheduleResult.Finished)
            {
                Console.WriteLine(sysInfo);
            }

            Console.WriteLine("Total Time to clear then readd : " + processTimer.ElapsedSeconds);

            Console.ReadLine();

            Console.WriteLine("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
            Console.WriteLine("Test 4 - Remove Individually and Register One at a time");

            processTimer.Start();

            copy.Reset();

            for (int i = 0; i < systems.Length; i++)
            {
                SystemInfo sysInf = systems[i];
                if (!sysInf.Active || sysInf.Type != type)
                {
                    continue;
                }
                copy.Remove(sysInf);
                copy.Add(sysInf);
            }
            processTimer.Stop();

            while (copy.NextSystem(0, out SystemInfo sysInfo) != ScheduleResult.Finished)
            {
                Console.WriteLine(sysInfo);
            }

            Console.WriteLine("Total Time to remove then readd : " + processTimer.ElapsedSeconds);

            Console.ReadLine();

            Console.WriteLine("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
            Console.WriteLine("Test 5 - System Run");

            schedule.Clear();

            for (int i = 0; i < systems.Length; i++)
            {
                SystemInfo sysInf = systems[i];
                if (!sysInf.Active || sysInf.Type != type)
                {
                    continue;
                }
                schedule.Add(sysInf);
            }

            double currentTime = 0;
            int    finishCount = 0;

            double[] endTimes = new double[laneCount];
            bool[]   finished = new bool[laneCount];
            averageTime = 0;

            processTimer.Start();
            while (!schedule.Finished && currentTime < time && finishCount < laneCount)
            {
                for (int i = 0; i < laneCount; i++)
                {
                    if (endTimes[i] <= currentTime && !finished[i])
                    {
                        unitTimer.Start();
                        schedule.FinishLane(i);
                        ScheduleResult result = schedule.NextSystem(i, out SystemInfo sysInf);

                        if (result == ScheduleResult.Supplied)
                        {
                            sysInf.Age = 0;
                            if (sysInf.AverageRunTime + currentTime > time)
                            {
                                finished[i] = true;
                                finishCount++;
                                unitTimer.Stop();
                                continue;
                            }
                            endTimes[i] = currentTime + sysInf.AverageRunTime;
                        }
                        else if (result == ScheduleResult.Finished)
                        {
                            finished[i] = true;
                            finishCount++;
                        }
                        unitTimer.Stop();
                        processTimer.Stop();
                        averageTime = MathHelper.MovingAverage(averageTime, unitTimer.ElapsedSeconds, i + 1);
                        unitTimer.Reset();
                        processTimer.Start();
                    }
                }

                processTimer.Stop();
                double nextTime = double.PositiveInfinity;
                for (int i = 0; i < laneCount; i++)
                {
                    if (endTimes[i] > currentTime && endTimes[i] < nextTime)
                    {
                        nextTime = endTimes[i];
                    }
                }
                if (nextTime != double.PositiveInfinity)
                {
                    currentTime = nextTime;
                }
                processTimer.Start();
            }
            processTimer.Stop();

            Console.WriteLine("Total Time to decide : " + processTimer.ElapsedSeconds);
            Console.WriteLine("Average Time to decide : " + averageTime);
            Console.WriteLine("Extrapolated Time to decide : " + (averageTime * typeCount));
            Console.WriteLine("Total Time Used : " + (currentTime) + "/" + time);
            processTimer.Reset();

            Console.ReadLine();
        }