Пример #1
0
        /// <summary>
        /// Creates an object for testing the PropertyAccessor class.
        /// </summary>
        /// <returns></returns>
        public static PropertyAccessorTestObject CreateTestObject()
        {
            PropertyAccessorTestObject testObject = new PropertyAccessorTestObject();

            testObject.Int = TEST_INTEGER;
            testObject.String = TEST_STRING;
            testObject.Bool = TEST_BOOL;
            testObject.Byte = TEST_BYTE;
            testObject.Char = TEST_CHAR;
            testObject.DateTime = TEST_DATETIME;
            testObject.Decimal = TEST_DECIMAL;
            testObject.Double = TEST_DOUBLE;
            testObject.Float = TEST_FLOAT;
            testObject.Long = TEST_LONG;
            testObject.Sbyte = TEST_SBYTE;
            testObject.Short = TEST_SHORT;
            testObject.ULong = TEST_ULONG;
            testObject.UShort = TEST_USHORT;
            testObject.List = new ArrayList(TEST_ARRAY);

            return testObject;
        }
Пример #2
0
        /// <summary>
        /// Creates an object for testing the PropertyAccessor class.
        /// </summary>
        /// <returns></returns>
        public static PropertyAccessorTestObject CreateTestObject()
        {
            PropertyAccessorTestObject testObject = new PropertyAccessorTestObject();

            testObject.Int      = TEST_INTEGER;
            testObject.String   = TEST_STRING;
            testObject.Bool     = TEST_BOOL;
            testObject.Byte     = TEST_BYTE;
            testObject.Char     = TEST_CHAR;
            testObject.DateTime = TEST_DATETIME;
            testObject.Decimal  = TEST_DECIMAL;
            testObject.Double   = TEST_DOUBLE;
            testObject.Float    = TEST_FLOAT;
            testObject.Long     = TEST_LONG;
            testObject.Sbyte    = TEST_SBYTE;
            testObject.Short    = TEST_SHORT;
            testObject.ULong    = TEST_ULONG;
            testObject.UShort   = TEST_USHORT;
            testObject.List     = new ArrayList(TEST_ARRAY);

            return(testObject);
        }
Пример #3
0
        /// <summary>
        /// Test the performance of getting an integer property.
        /// </summary>
        public static void TestGetIntegerPerformance()
        {
            PropertyAccessorTestObject testObject
                = CreateTestObject();

            int test = 0;

            //
            // Generic Property accessor
            //
            Stopwatch watch = new System.Diagnostics.Stopwatch();

            watch.Reset(); watch.Start();

            GenericPropertyAccessor <PropertyAccessorTestObject, int> propertyAccessor =
                new GenericPropertyAccessor <PropertyAccessorTestObject, int>("Int");

            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                test = propertyAccessor.Get(testObject);
            }

            watch.Stop();
            double genericPropertyAccessorMs = watch.ElapsedMilliseconds;

            //
            // Direct access
            //
            watch.Reset(); watch.Start();

            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                test = testObject.Int;
            }

            watch.Stop();
            double directAccessMs = watch.ElapsedMilliseconds;

            //
            // Property accessor
            //
            Type type = testObject.GetType();

            watch.Reset(); watch.Start();

            PropertyAccessor propertyAccessor2 = new PropertyAccessor(typeof(PropertyAccessorTestObject), "Int");

            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                test = (int)propertyAccessor2.Get(testObject);
            }

            watch.Stop();
            double propertyAccessorMs = watch.ElapsedMilliseconds;

            //
            // Print results
            //
            Console.WriteLine(
                TEST_ITERATIONS.ToString() + " property gets on integer..."
                + "\nDirect access ms: \t\t\t\t" + directAccessMs.ToString()
                + "\nGenericPropertyAccessor (Reflection.Emit) ms: \t" + genericPropertyAccessorMs.ToString()
                + "\nPropertyAccessor (Reflection.Emit) ms: \t\t" + propertyAccessorMs.ToString() + "\n\n");
        }
Пример #4
0
        /// <summary>
        /// Test the performance of setting a string property.
        /// </summary>
        public static void TestSetStringPerformance()
        {
            const string TEST_VALUE = "Test";

            PropertyAccessorTestObject testObject
                = CreateTestObject();

            //
            // Generic Property accessor
            //
            Stopwatch watch = new System.Diagnostics.Stopwatch();

            watch.Reset(); watch.Start();

            GenericPropertyAccessor <PropertyAccessorTestObject, string> propertyAccessor =
                new GenericPropertyAccessor <PropertyAccessorTestObject, string>("String");

            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                propertyAccessor.Set(testObject, TEST_VALUE);
            }

            watch.Stop();
            double genericPropertyAccessorMs = watch.ElapsedMilliseconds;

            //
            // Direct access
            //
            watch.Reset(); watch.Start();

            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                testObject.String = TEST_VALUE;
            }

            watch.Stop();
            double directAccessMs = watch.ElapsedMilliseconds;

            //
            // Property accessor
            //
            Type type = testObject.GetType();

            watch.Reset(); watch.Start();

            PropertyAccessor propertyAccessor2 = new PropertyAccessor(typeof(PropertyAccessorTestObject), "String");

            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                propertyAccessor2.Set(testObject, TEST_VALUE);
            }

            watch.Stop();
            double propertyAccessorMs = watch.ElapsedMilliseconds;

            //
            // Print results
            //
            Console.WriteLine(
                TEST_ITERATIONS.ToString() + " property sets on string..."
                + "\nDirect access ms: \t\t\t\t" + directAccessMs.ToString()
                + "\nGenericPropertyAccessor (Reflection.Emit) ms: \t" + genericPropertyAccessorMs.ToString()
                + "\nPropertyAccessor (Reflection.Emit) ms: \t\t" + propertyAccessorMs.ToString() + "\n\n");
        }