动态反射最新版本 4.0.9.22 性能报告


1. 反射调用 VS 动态编译调用 获取、设置值

 

循环次数: 100000

结果:

代码
------  Test started: Assembly: Pixysoft.Framework.Reflection.dll  ------

reflection
    Time Elapsed:        514ms
    CPU time:        
500 , 000 ,000ns
    Gen 
0 :              0
    Gen 
1 :              0
    Gen 
2 :              0

dynamic
    Time Elapsed:        366ms
    CPU time:        
234 , 375 ,000ns
    Gen 
0 :              132
    Gen 
1 :              1
    Gen 
2 :              0


1  passed,  0  failed,  0  skipped, took  1.11  seconds (Ad hoc).

 

结论:性能比较接近,证明反射的性能不是非常差。 

 

2.  AOP 使用IMessageSink的attribute模式 VS RealProxy VS DynamicProxy

循环: 10000

结果:

代码
------  Test started: Assembly: Pixysoft.Framework.Reflection.dll  ------

aop
    Time Elapsed:        961ms
    CPU time:        
953 , 125 ,000ns
    Gen 
0 :              71
    Gen 
1 :              0
    Gen 
2 :              0

real
    Time Elapsed:        72ms
    CPU time:        
78 , 125 ,000ns
    Gen 
0 :              8
    Gen 
1 :              0
    Gen 
2 :              0

dynamic
    Time Elapsed:        59ms
    CPU time:        
62 , 500 ,000ns
    Gen 
0 :              8
    Gen 
1 :              0
    Gen 
2 :              0


1  passed,  0  failed,  0  skipped, took  1.20  seconds (Ad hoc). 

比微软的RealProxy性能好一点点。 

 

3.  反射获取设置值 VS 动态编译获取设置值 VS BeanMap获取设置值

循环  100000

结果:

代码
------  Test started: Assembly: Pixysoft.Framework.Reflection.dll  ------

reflect
    Time Elapsed:        
2 ,703ms
    CPU time:        
2 , 671 , 875 ,000ns
    Gen 
0 :              39
    Gen 
1 :              0
    Gen 
2 :              0

dynamic
    Time Elapsed:        834ms
    CPU time:        
843 , 750 ,000ns
    Gen 
0 :              457
    Gen 
1 :              0
    Gen 
2 :              0

beanmap
    Time Elapsed:        861ms
    CPU time:        
828 , 125 ,000ns
    Gen 
0 :              205
    Gen 
1 :              0
    Gen 
2 :              0


1  passed,  0  failed,  0  skipped, took  4.52  seconds (Ad hoc).

 

 

性能上beanmap和dynamictype接近,但是处理方便。

 

4.  反射获取Type信息 VS 动态编译获取Type信息

循环  100000

结果:

代码
------  Test started: Assembly: Pixysoft.Framework.Reflection.dll  ------

reflection
    Time Elapsed:        268ms
    CPU time:        
250 , 000 ,000ns
    Gen 
0 :              72
    Gen 
1 :              0
    Gen 
2 :              0

emit with handler cache
    Time Elapsed:        229ms
    CPU time:        
218 , 750 ,000ns
    Gen 
0 :              19
    Gen 
1 :              0
    Gen 
2 :              0


1  passed,  0  failed,  0  skipped, took  0.59  seconds (Ad hoc). 

再次说明了,反射的性能实际上不差。 

 

5. RealProxy实现POJO VS 动态编译实现POJO VS 直接创建POJO

循环  100000

结果:

代码
------  Test started: Assembly: Pixysoft.Framework.Reflection.dll  ------

proxy
    Time Elapsed:        
3 ,090ms
    CPU time:        
2 , 843 , 750 ,000ns
    Gen 
0 :              498
    Gen 
1 :              0
    Gen 
2 :              0

dproxy dynamic constructor
    Time Elapsed:        122ms
    CPU time:        
125 , 000 ,000ns
    Gen 
0 :              47
    Gen 
1 :              1
    Gen 
2 :              0

direct
    Time Elapsed:        4ms
    CPU time:        0ns
    Gen 
0 :              2
    Gen 
1 :              0
    Gen 
2 :              0


1  passed,  0  failed,  0  skipped, took  3.41  seconds (Ad hoc).

 

 

可见动态编译的得到的对象再进行操作,性能是非常高的! 

你可能感兴趣的:(反射)