• 使用dynamic动态设置属性值与反射设置属性值性能对比


    static void Main(string[] args)
    
           {
               int times = 1000000;
     
               string value = "Dynamic VS  Reflection";
     
               //reflection 测试开始
               TestClass testTypeByReflection = new TestClass();
               Stopwatch watch1 = Stopwatch.StartNew();
               var property = typeof(TestClass).GetProperty("TestProperty");
               for (var i = 0; i < times; i++)
               {
                   property.SetValue(testTypeByReflection, value, null);
               }
               Console.WriteLine(string.Format("Reflection耗时:{0} 毫秒", watch1.ElapsedMilliseconds));
     
     
               //dynamic 测试开始
               Stopwatch watch2 = Stopwatch.StartNew();
               dynamic testTypeByDynamic = new TestClass();
               for (int i = 0; i < times; i++)
               {
                   testTypeByDynamic.TestProperty = value;
               }
               Console.WriteLine(string.Format("Dynamic耗时:{0} 毫秒", watch2.ElapsedMilliseconds));
     
               Console.ReadLine();
           }
    

      


    作者:RyanDing 
    出处:http://www.cnblogs.com/ryanding/ 
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。如有疑问,可以通过 ryan.d@qq.com 联系作者本人。

  • 相关阅读:
    信号的调制
    是否产生latch
    带通采样定理
    傅里叶变换
    信号与傅里叶(下)
    滤波器的相位和信号的时延
    信号与傅里叶级数
    阅读应该是主动的
    Matlab笔记—函数
    网络搭建---IP地址的设置及ping的使用
  • 原文地址:https://www.cnblogs.com/ProDoctor/p/6058989.html
Copyright © 2020-2023  润新知