예제 #1
0
        public static void SetStaticFields()
        {
            StaticByteField    = 0;
            StaticSByteField   = 1;
            StaticUInt16Field  = 2;
            StaticInt16Field   = 3;
            StaticUInt32Field  = 4;
            StaticInt32Field   = 5;
            StaticUInt64Field  = 6;
            StaticInt64Field   = 7;
            StaticDoubleField  = 8;
            StaticSingleField  = 9;
            StaticDecimalField = 10;
            StaticCharField    = 'a';
            StaticBooleanField = true;
            StaticStringField  = "testing";

            StaticObjectField   = new SimpleStruct(1111);
            StaticEnumField     = EnumInt64.B;
            StaticDateTimeField = new DateTime(50000);

            StaticSimpleStructField          = new SimpleStruct(1234);
            StaticSimpleGenericStructField   = new SimpleGenericStruct <ushort>(32);
            StaticNullableStructNotNullField = new SimpleStruct(56);
            StaticNullableStructNullField    = null;

            StaticSimpleClassField        = new SimpleClass(54);
            StaticSimpleGenericClassField = new SimpleGenericClass <string>("string");

            StaticSimpleInterfaceField = new ClassImplementSimpleInterface(87);
        }
예제 #2
0
        public void SetInstanceFields()
        {
            InstanceByteField    = 0;
            InstanceSByteField   = 1;
            InstanceUInt16Field  = 2;
            InstanceInt16Field   = 3;
            InstanceUInt32Field  = 4;
            InstanceInt32Field   = 5;
            InstanceUInt64Field  = 6;
            InstanceInt64Field   = 7;
            InstanceDoubleField  = 8;
            InstanceSingleField  = 9;
            InstanceDecimalField = 10;
            InstanceCharField    = 'a';
            InstanceBooleanField = true;
            InstanceStringField  = "testing";

            InstanceObjectField   = new SimpleStruct(1111);
            InstanceEnumField     = EnumInt64.B;
            InstanceDateTimeField = new DateTime(50000);

            InstanceSimpleStructField          = new SimpleStruct(1234);
            InstanceSimpleGenericStructField   = new SimpleGenericStruct <ushort>(32);
            InstanceNullableStructNotNullField = new SimpleStruct(56);
            InstanceNullableStructNullField    = null;

            InstanceSimpleClassField        = new SimpleClass(54);
            InstanceSimpleGenericClassField = new SimpleGenericClass <string>("string");

            InstanceSimpleInterfaceField = new ClassImplementSimpleInterface(87);
        }
예제 #3
0
 public void Set()
 {
     PublicField            = 100;
     ProtectedField         = 200;
     PrivateField           = 300;
     InterfaceField         = new ClassImplementSimpleInterface(0);
     InternalInterfaceField = new InternalClassImplementSimpleInterface();
 }
예제 #4
0
        public static void Main(string[] args)
        {
            uint amountOfSimpleClasses = (args.Length > 0 && args[0] != null) ? uint.Parse(args[0]) : 1000000;

            #region Initialize Test Array
            Timer timer = new Timer();
            List <SimpleClass> simpleClasses = new List <SimpleClass>();

            for (uint i = 0; i < amountOfSimpleClasses; i++)
            {
                simpleClasses.Add(new SimpleClass());
            }
            #endregion

            uint     repetition = (args.Length > 0 && args[1] != null) ? uint.Parse(args[1]) : 100;
            uint     counter    = repetition;
            double[] results    = new double[4];

            Console.WriteLine("Test;{0};{1}", amountOfSimpleClasses.ToString(), repetition.ToString());

            while (--counter > 0)
            {
                timer.StartRunning();
                simpleClasses.ForEach((SimpleClass simpleClass) =>
                {
                    if (simpleClass is SimpleInterface)
                    {
                        simpleClass.InterfaceMethod();
                    }
                });
                results[0] += timer.StopRunning();

                timer.StartRunning();
                simpleClasses.ForEach((SimpleClass simpleClass) =>
                {
                    if (simpleClass is SimpleInterface simple)
                    {
                        simple.InterfaceMethod();
                    }
                });
                results[1] += timer.StopRunning();

                timer.StartRunning();
                simpleClasses.ForEach((SimpleClass simpleClass) =>
                {
                    SimpleInterface simple = ((SimpleInterface)simpleClass);
                    if (simple != null)
                    {
                        simple.InterfaceMethod();
                    }
                });
                results[2] += timer.StopRunning();

                timer.StartRunning();
                simpleClasses.ForEach((SimpleClass simpleClass) =>
                {
                    SimpleInterface simple = simpleClass as SimpleInterface;
                    if (simple != null)
                    {
                        simple.InterfaceMethod();
                    }
                });
                results[3] += timer.StopRunning();
            }

            Console.WriteLine("Using IS;{0}", (results[0] / repetition).ToString());
            Console.WriteLine("Using IS + named variable;{0}", (results[1] / repetition).ToString());
            Console.WriteLine("Using simple cast;{0}", (results[2] / repetition).ToString());
            Console.WriteLine("Using AS;{0}", (results[3] / repetition).ToString());
        }