emit 代碼效能再最佳化。

來源:互聯網
上載者:User

最佳化前效能對比:

 

對象擷取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了

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.