Ejemplo n.º 1
0
        static long MeasureMaybeClassVsStruct()
        {
            const int iterations = 10000000;

            long ran = 0;

            CodeTimer.Time(true, "Maybe",
                           iterations,
                           () =>
            {
                var mh = new MaybeHost();
                ran   += mh.S.Length;
                ran   += mh.D.Month;
                ran   += mh.D2.Month;
            });

            CodeTimer.Time(true, "MaybeStruct",
                           iterations,
                           () =>
            {
                var mh = new MaybeStructHost();
                ran   += mh.S.Length;
                ran   += mh.D.Month;
                ran   += mh.D2.Month;
            });

            CodeTimer.Time(true, "Maybe Lazy",
                           iterations,
                           () =>
            {
                var lh = new MaybeLazyHost();
                ran   += lh.S.Length;
                ran   += lh.D.Month;
                ran   += lh.D2.Month;
            });

            CodeTimer.Time(true, "Lazy",
                           iterations,
                           () =>
            {
                var lh = new LazyHost();
                ran   += lh.S.Length;
                ran   += lh.D.Month;
                ran   += lh.D2.Month;
            });

            return(ran);
        }
Ejemplo n.º 2
0
        static long MeasureMaybeClassVsStruct()
        {
            const int iterations = 1000000;

            long ran = 0;

            CodeTimer.Time(true, "Maybe",
                iterations,
                () =>
                {
                    var mh = new MaybeHost();
                    ran += mh.S.Length;
                    ran += mh.D.Month;
                    ran += mh.D2.Month;
                });

            CodeTimer.Time(true, "MaybeStruct",
                iterations,
                () =>
                {
                    var mh = new MaybeStructHost();
                    ran += mh.S.Length;
                    ran += mh.D.Month;
                    ran += mh.D2.Month;
                });

            CodeTimer.Time(true, "Maybe Lazy",
                iterations,
                () =>
                {
                    var lh = new MaybeLazyHost();
                    ran += lh.S.Length;
                    ran += lh.D.Month;
                    ran += lh.D2.Month;
                });

            CodeTimer.Time(true, "Lazy",
                iterations,
                () =>
                {
                    var lh = new LazyHost();
                    ran += lh.S.Length;
                    ran += lh.D.Month;
                    ran += lh.D2.Month;
                });

            return ran;
        }