c# – System.Reflection vs Generics – 性能
我即将在服务器应用程序上编写一组方法,这些方法接收从TCP套接字接收的消息,对它们进行编码/解码,并加密/解密它们.
考虑将消息定义为特殊类型,每个消息都有自己的属性集和总长度,我需要选择以下解决方案之一: 我对解决方案#2更感兴趣,因为它使我的代码缩小了30倍.但是,我担心不断反映属性是否会影响性能.现在由于时间限制完成项目,我无法真正“实验”. 我将非常感谢任何个人经验或与基准测试相关的性能与任何一种解决方案的关系. 解决方法
反思可以足够快.但需要正确实施.
反思表现 – 快速和轻便的功能 typeof Object.GetType typeof == Object.GetType Type equivalence APIs (including typehandle operator overloads) get_Module get_MemberType Some of the IsXX predicate APIs New token/handle resolution APIs in the .NET Framework 2.0 昂贵的功能 GetXX APIs (MethodInfo,PropertyInfo,FieldInfo,and so on) GetCustomAttributes Type.InvokeMember Invoke APIs (MethodInfo.Invoke,FieldInfo.GetValue,and so on) get_Name (Name property) Activator.CreateInstance Source – Dodge Common Performance Pitfalls to Craft Speedy Applications MethodInfo可以加速 – Improving performance reflection,what alternatives should I consider 好的链接: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |