最佳化前效能對比:
對象擷取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了