Beispiel #1
0
        public void ReflectEffiencyTest()
        {
            // init
            DateTime now = DateTime.Now;
            CTester obj = new CTester();
            Type type = typeof(CTester);
            TimeSpan elapse;

            // direct method invoke
            now = DateTime.Now;
            for (int i = 0; i < 1000000; i++)
            {
                obj.test1();
            }
            elapse = DateTime.Now - now;
            Console.WriteLine("direct method invoke: " + elapse.TotalMilliseconds);

            // reflect method invoke
            now = DateTime.Now;
            MethodInfo method = type.GetMethod("test1");
            for (int i = 0; i < 1000000; i++)
            {
                method.Invoke(obj, BindingFlags.InvokeMethod, null,null,null);
            }
            elapse = DateTime.Now - now;
            Console.WriteLine("reflect method invoke: " + elapse.TotalMilliseconds);

            // fast reflect method invoke
            now = DateTime.Now;
            MethodInfo methodInfo = type.GetMethod("test1");
            FastMethodInvoker.FastInvokeHandler fastInvoker = FastMethodInvoker.FastInvoker.GetMethodInvoker(methodInfo);
            for (int i = 0; i < 1000000; i++)
            {
                fastInvoker(obj, null);
            }
            elapse = DateTime.Now - now;
            Console.WriteLine("fast reflect method invoke: " + elapse.TotalMilliseconds);

            // direct property access
            for (int i = 0; i < 1000000; i++)
            {
                int id = obj.Id;
            }
            elapse = DateTime.Now - now;
            Console.WriteLine("direct property access: " + elapse.TotalMilliseconds);

            // reflect method invoke
            now = DateTime.Now;
            PropertyInfo prop = type.GetProperty("Id");
            for (int i = 0; i < 1000000; i++)
            {
                int id = (int)prop.GetValue(obj, null);
            }
            elapse = DateTime.Now - now;
            Console.WriteLine("reflect property access: " + elapse.TotalMilliseconds);
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     BeetleX.FastHttpApi.HttpClientPoolFactory.SetPoolSize(Host, 20, 50);
     CTester.RunTest <FastHttpClientTest>(20, 1000000);
     Console.Read();
 }