Exemple #1
0
        static CountedStopwatch TimeFor_ClassConstraint_NullCheck_HoistedCount <T>(T list)
            where T : class, IList <string>
        {
            // just need something for the compiler to guarantee that list is not null.
            if (list == null)
            {
                throw new ArgumentNullException();
            }

            var timer = new CountedStopwatch(TestName("Generic caller - for (class constraint, null check, hoisted count)", list.GetType(), typeof(T)));

            for (int i = 0; i < TimedIntervals; i++)
            {
                timer.Start();

                int count = list.Count;
                for (int j = 0; j < count; j++)
                {
                    var item = list[j];
                    DontElide(item);
                }

                timer.Stop();
            }

            return(timer);
        }
Exemple #2
0
        static CountedStopwatch Time_Foreach_List(List <string> list)
        {
            var timer = new CountedStopwatch(TestName("foreach", list.GetType()));

            for (int i = 0; i < TimedIntervals; i++)
            {
                timer.Start();

                foreach (var item in list)
                {
                    DontElide(item);
                }

                timer.Stop();
            }

            return(timer);
        }
Exemple #3
0
        static CountedStopwatch TimeForeach_Dynamic(dynamic list)
        {
            var timer = new CountedStopwatch(TestName("foreach (dynamic)", list.GetType()));

            for (int i = 0; i < TimedIntervals; i++)
            {
                timer.Start();

                foreach (var item in list)
                {
                    DontElide(item);
                }

                timer.Stop();
            }

            return(timer);
        }
Exemple #4
0
        static CountedStopwatch Time_Foreach_YieldEnumerator(ReadOnlyCollectionYieldEnumerator <string> list)
        {
            var timer = new CountedStopwatch(TestName("foreach", list.GetType()));

            for (int i = 0; i < TimedIntervals; i++)
            {
                timer.Start();

                foreach (var item in list)
                {
                    DontElide(item);
                }

                timer.Stop();
            }

            return(timer);
        }
Exemple #5
0
        static CountedStopwatch Time_For_List(List <string> list)
        {
            var timer = new CountedStopwatch(TestName("for", list.GetType()));

            for (int i = 0; i < TimedIntervals; i++)
            {
                timer.Start();

                for (int j = 0; j < list.Count; j++)
                {
                    var item = list[j];
                    DontElide(item);
                }

                timer.Stop();
            }

            return(timer);
        }
Exemple #6
0
        static CountedStopwatch TimeForeach_ClassConstraint <T>(T list)
            where T : class, IList <string>
        {
            var timer = new CountedStopwatch(TestName("Generic caller - foreach (class constraint)", list.GetType(), typeof(T)));

            for (int i = 0; i < TimedIntervals; i++)
            {
                timer.Start();

                foreach (var item in list)
                {
                    DontElide(item);
                }

                timer.Stop();
            }

            return(timer);
        }
Exemple #7
0
        static CountedStopwatch TimeFor <T>(T list)
            where T : IList <string>
        {
            var timer = new CountedStopwatch(TestName("Generic caller - for", list.GetType(), typeof(T)));

            for (int i = 0; i < TimedIntervals; i++)
            {
                timer.Start();

                for (int j = 0; j < list.Count; j++)
                {
                    var item = list[j];
                    DontElide(item);
                }

                timer.Stop();
            }

            return(timer);
        }
Exemple #8
0
        static CountedStopwatch Time_For_IList_HoistedCount(IList <string> list)
        {
            var timer = new CountedStopwatch(TestName("for (Hoisted Count)", list.GetType(), typeof(IList <string>)));

            for (int i = 0; i < TimedIntervals; i++)
            {
                timer.Start();

                int count = list.Count;
                for (int j = 0; j < count; j++)
                {
                    var item = list[j];
                    DontElide(item);
                }

                timer.Stop();
            }

            return(timer);
        }
Exemple #9
0
        static CountedStopwatch TimeFor_Dynamic(dynamic list)
        {
            var timer = new CountedStopwatch(TestName("for (dynamic)", list.GetType()));

            for (int i = 0; i < TimedIntervals; i++)
            {
                timer.Start();

                int count = list is Array ? list.Length : list.Count;

                for (int j = 0; j < count; j++)
                {
                    var item = list[j];
                    DontElide(item);
                }

                timer.Stop();
            }

            return(timer);
        }