• 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了

  • 相关阅读:
    leetcode 153. Find Minimum in Rotated Sorted Array 寻找旋转排序数组中的最小值(中)
    Python写实用小工具实现图片转字符画
    leetcode 215. Kth Largest Element in an Array 数组中的第K个最大元素
    leetcode 75. Sort Colors 颜色分类
    leetcode 347. Top K Frequent Elements 前 K 个高频元素
    记一次 异常断电导致测试服务器无法正常启动,默认进入救援模式(Redhat 7.8)
    NTP: 时钟源管理
    获取MobaXterm 保存的账号密码
    k8s 问题记录:MYSQL_USER="root", MYSQL_PASSWORD cannot be used for the root user
    K8S报错整理_kubectl: Error from server: error dialing backend: remote error: tls: internal error
  • 原文地址:https://www.cnblogs.com/zc22/p/1752904.html
Copyright © 2020-2023  润新知