emit 代码性能再优化。
优化前性能对比:
对象获取dummy结构对比
ObjectWithValueAndAttribute p = new ObjectWithValueAndAttribute();
100000
------ Test started: Assembly: Pixysoft.Framework.Reflection.dll ------
reflection
Time Elapsed: 4,589ms
CPU time: 4,015,625,000ns
Gen 0: 484
Gen 1: 0
Gen 2: 0
emit direct call handler
Time Elapsed: 1,406ms
CPU time: 1,359,375,000ns
Gen 0: 1067
Gen 1: 0
Gen 2: 0
emit with handler cache
Time Elapsed: 1,589ms
CPU time: 1,562,500,000ns
Gen 0: 1080
Gen 1: 0
Gen 2: 0
1 passed, 0 failed, 0 skipped, took 7.80 seconds (Ad hoc).
序列化性能对比:
ObjectWithValue pojo = CreateMyPojo();
5000
------ Test started: Assembly: Pixysoft.Framework.Configurations.dll ------
xml serialize
Time Elapsed: 877ms
CPU time: 859,375,000ns
Gen 0: 64
Gen 1: 0
Gen 2: 0
dynamic serialize
Time Elapsed: 395ms
CPU time: 375,000,000ns
Gen 0: 238
Gen 1: 1
Gen 2: 0
direct serialize
Time Elapsed: 94ms
CPU time: 93,750,000ns
Gen 0: 139
Gen 1: 0
Gen 2: 0
1 passed, 0 failed, 0 skipped, took 1.47 seconds (Ad hoc).
反序列化性能对比
ObjectWithValue pojo = CreateMyPojo();
5000
------ Test started: Assembly: Pixysoft.Framework.Configurations.dll ------
xml deserialize
Time Elapsed: 916ms
CPU time: 890,625,000ns
Gen 0: 60
Gen 1: 0
Gen 2: 0
dynamic deserialize
Time Elapsed: 359ms
CPU time: 359,375,000ns
Gen 0: 179
Gen 1: 0
Gen 2: 0
1 passed, 0 failed, 0 skipped, took 1.44 seconds (Ad hoc).
反序列化性能对比
ObjectWithCollecton pojo = CreateMyPojo3();
500
------ Test started: Assembly: Pixysoft.Framework.Configurations.dll ------
xml deserialize
Time Elapsed: 1,688ms
CPU time: 1,671,875,000ns
Gen 0: 121
Gen 1: 0
Gen 2: 0
dynamic deserialize
Time Elapsed: 233ms
CPU time: 218,750,000ns
Gen 0: 42
Gen 1: 0
Gen 2: 0
1 passed, 0 failed, 0 skipped, took 2.14 seconds (Ad hoc).
插件性能对比
IPerson p = new Person();
500
------ Test started: Assembly: Pixysoft.Framework.Plugins.dll ------
xml deserialize
Time Elapsed: 24,890ms
CPU time: 17,937,500,000ns
Gen 0: 1497
Gen 1: 2
Gen 2: 0
proxy deserialize
Time Elapsed: 9,447ms
CPU time: 3,390,625,000ns
Gen 0: 441
Gen 1: 1
Gen 2: 0
1 passed, 0 failed, 0 skipped, took 35.08 seconds (Ad hoc).
REMOTING性能对比
IRemotingValue value = Pixysoft.Tools.PojoHelper.GetPojo<IRemotingValue>();
500
------ Test started: Assembly: Pixysoft.Framework.Remoting.dll ------
reflect
Time Elapsed: 7,236ms
CPU time: 2,125,000,000ns
Gen 0: 155
Gen 1: 0
Gen 2: 0
dynamic
Time Elapsed: 7,520ms
CPU time: 1,765,625,000ns
Gen 0: 130
Gen 1: 0
Gen 2: 0
1 passed, 0 failed, 0 skipped, took 14.95 seconds (Ad hoc).
小结:
本次无意义的优化最终浪费了3个小时。原来性能问题在日志上。开启了日志后,消耗了1.6秒。
而优化的代码只是从0.5毫秒 -》 0.1毫秒。 解决了0.4毫秒。几乎等于没有优化。。
看来需要一个强大的profiler tool了
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
· 你所不知道的 C/C++ 宏知识
· 聊一聊 操作系统蓝屏 c0000102 的故障分析
· DeepSeek V3 两周使用总结
· 回顾我的软件开发经历(1)
· C#使用yield关键字提升迭代性能与效率
· 低成本高可用方案!Linux系统下SQL Server数据库镜像配置全流程详解
· 4. 使用sql查询excel内容