1. 反射序列化與動態編譯序列化。
比較結果:
------ Test started: Assembly: Pixysoft.Framework.Configurations.dll ------
Begin CreateObjectUsingReflection
Begin CreateObjectUsingReflection
00:00:04.2031250
Begin CreateObjectUsingReflection
Begin CreateObjectUsingReflection
00:00:07.8593750
Begin CreateObjectUsingReflection
Begin CreateObjectUsingReflection
00:00:07.2187500
1 passed, 0 failed, 0 skipped, took 19.36 seconds (Ad hoc).
使用c#提供的序列化最快,而反射序列化和動態編譯序列化差不多。證明了反射獲取數據在序列化中的比重並不大。
------------------------------
2. 反射序列化與完全動態建立序列化適配器比較
所謂建立序列化適配器,就是針對不同的對象,內存建立一個針對的獲取數據的對象,這樣就不需要通過反射獲取屬性,而是等效於直接獲取。
------ Test started: Assembly: Pixysoft.Framework.Configurations.dll ------
Begin CreateObjectUsingReflection
Begin CreateObjectUsingReflection
00:00:04.1406250
Begin CreateObjectUsingReflection
Begin CreateObjectUsingReflection
00:00:08
Begin CreateObjectUsingReflection
Begin CreateObjectUsingReflection
00:00:07.5468750
Begin CreateObjectUsingReflection
Begin CreateObjectUsingReflection
00:00:01.1250000
1 passed, 0 failed, 0 skipped, took 20.91 seconds (Ad hoc).
可見如果是直接獲取值,速度最快。 提升大概4倍(50000次循環。)
----------------------
3. 比較IMessageSInk和直接獲取數據性能。
循環10w次,結果是:
Begin CreateObjectUsingReflection
00:00:11.2187500
Begin CreateObjectUsingReflection
Begin CreateObjectUsingReflection
00:00:00.0156250
提升了接近1000倍。。。。暈倒了。