<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      反射(Reflection)的性能分析

      記得老早以前就看到有人把反射稱之為“性能殺手",正好目前正在做的erp系統為了實現擴展,系統就是架構在反射的基礎之上,數據交互也都是通過反射來實現。首先系統會產生太多dll,現在剛剛起步,已經高達43個之多,由于erp系統具有很復雜的業務功能,產品在發布階段很可能產生200甚至更多的dll,且不說這幾百個項目在調試的時候,漫長的等待是多么的痛苦,在產品推出去之后,這么多的dll的版本如何維護?多現在為止,除了windows還沒有見過dll超過百的系統,難道我們的系統真的比windows還要難?這些暫且不提,先測試一下反射在系統應用的性能情況,測試程序如下:

      //被測試類
      using System;
      using System.Collections.Generic;
      using System.Text;

      namespace ClassLibrary1
      {
          
      public class CTester
          
      {
              
      public CTester()
              
      {
                  a 
      = 10;
              }



              
      public void test1()
              
      {
                  a 
      = (a - 0.0001* 1.0001;
              }

              
      private double a;
              
      public double geta() return a; }
          }

      }



      ///測試類
      using System;
      using System.Collections.Generic;
      using System.Text;
      using System.Reflection;
      using System.Collections;

      namespace ConsoleApplication2
      {
         
              
      public class CTester
              
      {
                  
      public CTester()
                  
      {
                      a 
      = 10;
                  }

              

                  
      public void test1()
                  
      {
                      a 
      = (a - 0.0001* 1.0001;
                  }

                  
      private double a;
                  
      public double geta() return a; }
              }


         


          
      class Program
          
      {
              
      private string test1()
              
      {
                  
      int now = System.Environment.TickCount;
                 
                  
      for (int i = 0; i < 1000; i++)
                  
      {
                      
      for (int j = 0; j < 100; j++)
                      
      {
                          CTester aTest 
      = new CTester();
                          aTest.test1();
                          
                      }

                  }


                  
      string time = (System.Environment.TickCount - now).ToString();
                  
      return time;
              }

              
      static Hashtable table = new Hashtable();
              
      private string test3()
              
      {
                  
      int now = System.Environment.TickCount;
                 
                  
      for (int i = 0; i < 1000; i++)
                  
      {
                      
      for (int j = 0; j < 100; j++)
                      
      {
                          Type theTest 
      = null;
                          
      if (table.ContainsKey("ConsoleApplication2.CTester"))
                          
      {
                              theTest 
      = table["ConsoleApplication2.CTester"as Type;
                          }

                          
      else
                          
      {
                              theTest 
      = Type.GetType("ConsoleApplication2.CTester");
                              table.Add(
      "ConsoleApplication2.CTester", theTest);
                          }

                          ConsoleApplication2.CTester theobj 
      = theTest.InvokeMember(null, BindingFlags.CreateInstance
                              , 
      nullnullnullas ConsoleApplication2.CTester;
                          theobj.test1();
                      }

                  }


                  
      string  time =(System.Environment.TickCount - now).ToString();
                  
      return  time;
              }

              
      private string test2()
              
      {
                  
      int now = System.Environment.TickCount;
                  
      for (int i = 0; i < 1000; i++)
                  
      {
                      
      for (int j = 0; j < 100; j++)
                      
      {
                          Type theTest 
      = theTest = Type.GetType("ConsoleApplication2.CTester"); ;
                          ConsoleApplication2.CTester theobj 
      = theTest.InvokeMember(null, BindingFlags.CreateInstance
                              , 
      nullnullnullas ConsoleApplication2.CTester;
                          theobj.test1();
                      }

                  }


                  
      string  time =(System.Environment.TickCount - now).ToString();
                  
      return time;
              }

                
      static object InvokeMehod(string FileName,
                  
      string MethodName,
                  
      object[] Args)
              
      {
                  Assembly a 
      = Assembly.LoadFrom(FileName);


                  MethodInfo method 
      = null;
                  Type HereType 
      = null;
                  
      foreach (Module m in a.GetModules())
                  
      {
                      
      foreach (Type t in m.GetTypes())
                      
      {

                          
      foreach (MethodInfo mInfo in t.GetMethods())
                          
      {
                              
      if (mInfo.Name == MethodName)
                              
      {
                                  ParameterInfo[] pInfo 
      = mInfo.GetParameters();
                                  
      if (pInfo.Length == Args.Length)
                                  
      {
                                      
      bool same = true;
                                      
      for (int i = 0; i < pInfo.Length; i++)
                                      
      {
                                          
      if (Args[i] != null && pInfo[i].ParameterType != typeof(object)
                                              
      && pInfo[i].ParameterType != typeof(object[]))
                                          
      {
                                              
      if (pInfo[i].ParameterType != Args[i].GetType())
                                              
      {
                                                  same 
      = false;
                                              }

                                          }

                                      }

                                      
      if (same)
                                      
      {
                                          HereType 
      = t;
                                          method 
      = mInfo;
                                      }

                                  }

                              }


                              
      if (method != null)
                              
      {
                                  
      break;
                              }

                          }


                          
      if (method != null)
                          
      {
                              
      break;
                          }

                      }


                      
      if (method != null)
                      
      {
                          
      break;
                      }

                  }


                  
      if (method == null)
                  
      {
                      
      //Log.LogException(typeof(Excute), "沒有發現:" + FileName + "/" + MethodName, new Exception("沒有發現:" + FileName + "/" + MethodName));
                      return null;
                  }


                  
      object ins = null;
                  
      if (!method.IsStatic)
                  
      {
                      ins 
      = a.CreateInstance(HereType.FullName);
                  }

                  
      object RetObject = method.Invoke(ins, Args);
                  
      return RetObject;
              }

          

              
      private string test5()
              
      {
                  
      int now = System.Environment.TickCount;
                  
      for (int i = 0; i < 1000; i++)
                  
      {
                      
      for (int j = 0; j < 100; j++)
                      
      {
                          InvokeMehod(
      @"D:\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2\bin\Debug\ClassLibrary1.dll""test1"new object[] { });
                      }

                  }


                  
      string time = (System.Environment.TickCount - now).ToString();
                  
      return time;
              }

              
      static void Main(string[] args)
              
      {
                  Program p 
      = new Program();
                  
      string ticks = p.test1();
                  Console.WriteLine(
      "用編譯器執行:"+ticks);
                  
      string t = p.test2();
                  Console.WriteLine(
      "用反射執行"+t);
                  
      string t1 = p.test3();
                  Console.WriteLine(
      "優化之后的反射:"+t1);
                  
      string t2 = p.test5();
                  Console.WriteLine(
      "加載程序集并反射:"+t2);
                  
      if (ticks.ToString() == "0")
                  
      {
                      Console.WriteLine(
      "反射/編譯: 不在一個級別上面");
                  }

                  
      else
                  
      {
                      Console.WriteLine(
      "反射/編譯 =" + (Convert.ToInt32(t) / Convert.ToInt32(ticks)).ToString());
                  }

           
                  
      if (ticks.ToString() == "0")
                  
      {
                      Console.WriteLine(
      "加載程序集并反射/編譯: 不在一個級別上面");
                  }

                  
      else
                  
      {
                      Console.WriteLine(
      "加載程序集并反射/編譯 =" + (Convert.ToInt32(t2) / Convert.ToInt32(ticks)).ToString());
                  }

                 

                  Console.WriteLine(
      "加載程序集并反射/反射 =" + (Convert.ToInt32(t2) / Convert.ToInt32(t)).ToString());
                 
                  Console.Read();
              }

          }

      }

      測試結果為:

      638倍的性能損失,不知道算大算小,反正項目經理說無所謂。
      赫赫,無(。。)者無畏

      posted @ 2006-08-10 14:50  Robin Zhang  閱讀(5854)  評論(41)    收藏  舉報
      主站蜘蛛池模板: 亚州中文字幕一区二区| 亚洲乱码日产精品一二三| 激情人妻中出中文字幕一区| 人妻系列无码专区69影院| 国产精品推荐视频一区二区| 久久亚洲精品无码va白人极品| 中文字幕av日韩有码| 亚洲熟女乱色一区二区三区| 国产精品亚洲二区在线播放| 日本中文字幕有码在线视频 | 国产精品人成视频免费国产| 亚洲经典av一区二区| 国产在线午夜不卡精品影院 | 亚洲熟妇色xxxxx亚洲| 国产福利视频区一区二区| 丰满少妇内射一区| 华人在线亚洲欧美精品| 久久婷婷综合色丁香五月| 中文一区二区视频| 国产激情一区二区三区四区| 亚洲夂夂婷婷色拍WW47| 亚洲精品电影院| 国产精品久久中文字幕| 99亚洲男女激情在线观看| 国产精品蜜臀av在线一区| 亚洲日韩久久综合中文字幕| 日韩精品av一区二区三区| 国产视色精品亚洲一区二区| 国产一区二区黄色在线观看| 国产99在线 | 亚洲| 老色鬼在线精品视频在线观看| 久久精品国产中文字幕| 亚洲精品日韩在线丰满| 久操热在线视频免费观看| 丰顺县| 亚洲在av极品无码天堂| 无码国内精品人妻少妇| 日韩中文字幕人妻精品| 国产av一区二区麻豆熟女| 在线看免费无码的av天堂| 日韩中文字幕人妻精品|