예제 #1
0
        public override int Run(string[] remainingArguments)
        {
            Benchmark benchmark;

            if (_isGet == true && _isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new GetValueTypeStaticFieldValueBenchmark();
            }
            else if (_isGet == true && !_isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new GetReferenceTypeStaticFieldValueBenchmark();
            }
            else if (_isGet == true && _isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new GetValueTypeStaticPropertyValueBenchmark();
            }
            else if (_isGet == true && !_isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new GetReferenceTypeStaticPropertyValueBenchmark();
            }
            else if (_isGet == true && _isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new GetValueTypeInstanceFieldValueBenchmark();
            }
            else if (_isGet == true && !_isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new GetReferenceTypeInstanceFieldValueBenchmark();
            }
            else if (_isGet == true && _isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new GetValueTypeInstancePropertyValueBenchmark();
            }
            else if (_isGet == true && !_isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new GetReferenceTypeInstancePropertyValueBenchmark();
            }
            else if (_isGet == false && _isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new SetValueTypeStaticFieldValueBenchmark();
            }
            else if (_isGet == false && !_isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new SetReferenceTypeStaticFieldValueBenchmark();
            }
            else if (_isGet == false && _isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new SetValueTypeStaticPropertyValueBenchmark();
            }
            else if (_isGet == false && !_isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new SetReferenceTypeStaticPropertyValueBenchmark();
            }
            else if (_isGet == false && _isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new SetValueTypeInstanceFieldValueBenchmark();
            }
            else if (_isGet == false && !_isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new SetReferenceTypeInstanceFieldValueBenchmark();
            }
            else if (_isGet == false && _isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new SetValueTypeInstancePropertyValueBenchmark();
            }
            else if (_isGet == false && !_isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new SetReferenceTypeInstancePropertyValueBenchmark();
            }
            //else if (_isValueType && _benchmarkType == BenchmarkType.Constructor)
            //{
            //    benchmark = new InvokeValueTypeConstructorBenchmark();
            //}
            //else if (!_isValueType && _benchmarkType == BenchmarkType.Constructor)
            //{
            //    benchmark = new InvokeReferenceTypeConstructorBenchmark();
            //}
            else
            {
                return(1);
            }

            Console.WriteLine(benchmark.Name);

            benchmark.Execute(_factor);

            Console.WriteLine("  Times:");
            Console.WriteLine("    Direct Access:                {0}", benchmark.DirectAccessTime);
            Console.WriteLine("    Reflection:                   {0}", benchmark.ReflectionTime);
            Console.WriteLine("    Strongly-typed Reflectinator: {0}", benchmark.ReflectinatorStronglyTypedTime);
            Console.WriteLine("    Loosely-typed Reflectinator:  {0}", benchmark.ReflectinatorLooselyTypedTime);
            Console.WriteLine("  Ratio of N / Direct Access:");
            Console.WriteLine("    Reflection:                   {0:0.00}", benchmark.ReflectionTime.TotalMilliseconds / benchmark.DirectAccessTime.TotalMilliseconds);
            Console.WriteLine("    Strongly-typed Reflectinator: {0:0.00}", benchmark.ReflectinatorStronglyTypedTime.TotalMilliseconds / benchmark.DirectAccessTime.TotalMilliseconds);
            Console.WriteLine("    Loosely-typed Reflectinator:  {0:0.00}", benchmark.ReflectinatorLooselyTypedTime.TotalMilliseconds / benchmark.DirectAccessTime.TotalMilliseconds);
            Console.WriteLine("  Ratio of Reflection / N:");
            Console.WriteLine("    Direct Access                 {0:0.00}", benchmark.ReflectionTime.TotalMilliseconds / benchmark.DirectAccessTime.TotalMilliseconds);
            Console.WriteLine("    Strongly-typed Reflectinator: {0:0.00}", benchmark.ReflectionTime.TotalMilliseconds / benchmark.ReflectinatorStronglyTypedTime.TotalMilliseconds);
            Console.WriteLine("    Loosely-typed Reflectinator:  {0:0.00}", benchmark.ReflectionTime.TotalMilliseconds / benchmark.ReflectinatorLooselyTypedTime.TotalMilliseconds);

            return(0);
        }
        public override int Run(string[] remainingArguments)
        {
            Benchmark benchmark;

            if (_isGet == true && _isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new GetValueTypeStaticFieldValueBenchmark();
            }
            else if (_isGet == true && !_isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new GetReferenceTypeStaticFieldValueBenchmark();
            }
            else if (_isGet == true && _isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new GetValueTypeStaticPropertyValueBenchmark();
            }
            else if (_isGet == true && !_isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new GetReferenceTypeStaticPropertyValueBenchmark();
            }
            else if (_isGet == true && _isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new GetValueTypeInstanceFieldValueBenchmark();
            }
            else if (_isGet == true && !_isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new GetReferenceTypeInstanceFieldValueBenchmark();
            }
            else if (_isGet == true && _isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new GetValueTypeInstancePropertyValueBenchmark();
            }
            else if (_isGet == true && !_isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new GetReferenceTypeInstancePropertyValueBenchmark();
            }
            else if (_isGet == false && _isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new SetValueTypeStaticFieldValueBenchmark();
            }
            else if (_isGet == false && !_isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new SetReferenceTypeStaticFieldValueBenchmark();
            }
            else if (_isGet == false && _isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new SetValueTypeStaticPropertyValueBenchmark();
            }
            else if (_isGet == false && !_isValueType && _isStatic == true && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new SetReferenceTypeStaticPropertyValueBenchmark();
            }
            else if (_isGet == false && _isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new SetValueTypeInstanceFieldValueBenchmark();
            }
            else if (_isGet == false && !_isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Field)
            {
                benchmark = new SetReferenceTypeInstanceFieldValueBenchmark();
            }
            else if (_isGet == false && _isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new SetValueTypeInstancePropertyValueBenchmark();
            }
            else if (_isGet == false && !_isValueType && _isStatic == false && _benchmarkType == BenchmarkType.Property)
            {
                benchmark = new SetReferenceTypeInstancePropertyValueBenchmark();
            }
            //else if (_isValueType && _benchmarkType == BenchmarkType.Constructor)
            //{
            //    benchmark = new InvokeValueTypeConstructorBenchmark();
            //}
            //else if (!_isValueType && _benchmarkType == BenchmarkType.Constructor)
            //{
            //    benchmark = new InvokeReferenceTypeConstructorBenchmark();
            //}
            else
            {
                return 1;
            }

            Console.WriteLine(benchmark.Name);

            benchmark.Execute(_factor);

            Console.WriteLine("  Times:");
            Console.WriteLine("    Direct Access:                {0}", benchmark.DirectAccessTime);
            Console.WriteLine("    Reflection:                   {0}", benchmark.ReflectionTime);
            Console.WriteLine("    Strongly-typed Reflectinator: {0}", benchmark.ReflectinatorStronglyTypedTime);
            Console.WriteLine("    Loosely-typed Reflectinator:  {0}", benchmark.ReflectinatorLooselyTypedTime);
            Console.WriteLine("  Ratio of N / Direct Access:");
            Console.WriteLine("    Reflection:                   {0:0.00}", benchmark.ReflectionTime.TotalMilliseconds / benchmark.DirectAccessTime.TotalMilliseconds);
            Console.WriteLine("    Strongly-typed Reflectinator: {0:0.00}", benchmark.ReflectinatorStronglyTypedTime.TotalMilliseconds / benchmark.DirectAccessTime.TotalMilliseconds);
            Console.WriteLine("    Loosely-typed Reflectinator:  {0:0.00}", benchmark.ReflectinatorLooselyTypedTime.TotalMilliseconds / benchmark.DirectAccessTime.TotalMilliseconds);
            Console.WriteLine("  Ratio of Reflection / N:");
            Console.WriteLine("    Direct Access                 {0:0.00}", benchmark.ReflectionTime.TotalMilliseconds / benchmark.DirectAccessTime.TotalMilliseconds);
            Console.WriteLine("    Strongly-typed Reflectinator: {0:0.00}", benchmark.ReflectionTime.TotalMilliseconds / benchmark.ReflectinatorStronglyTypedTime.TotalMilliseconds);
            Console.WriteLine("    Loosely-typed Reflectinator:  {0:0.00}", benchmark.ReflectionTime.TotalMilliseconds / benchmark.ReflectinatorLooselyTypedTime.TotalMilliseconds);

            return 0;
        }