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了

 

posted @ 2010-06-06 23:46    阅读(500)  评论(0编辑  收藏  举报
IT民工