zoukankan      html  css  js  c++  java
  • 性能提升成功!!!!开帖留念!!!


    原来的序列化使用微软的。可是接口、内部类无法序列化,根本没法用。

    后来使用了自己的xml技术+反射,可是性能非常的垃圾。

    于是用了1天时间写了个emit框架,性能大幅度提升!

    对比结果:

    代码
            public void test002()
            {
                MyPojo2 pojo 
    = CreateMyPojo();

                StartTest(
    "Begin CreateObjectUsingReflection");

                
    for (int i = 0; i < 50000; i++)
                {
                    
    object content = Pixysoft.IO.XmlExporter.Instance.XmlSerialize(pojo);
                }

                EndTest(
    "Begin CreateObjectUsingReflection");

                StartTest(
    "Begin CreateObjectUsingReflection");

                
    for (int i = 0; i < 50000; i++)
                {
                    
    object content = XmlManager.Serialize(pojo);
                }

                EndTest(
    "Begin CreateObjectUsingReflection");

                StartTest(
    "Begin CreateObjectUsingReflection");

                
    for (int i = 0; i < 50000; i++)
                {
                    
    object content = XmlManager.DynamicSerialize(pojo);
                }

                EndTest(
    "Begin CreateObjectUsingReflection");

                StartTest(
    "Begin CreateObjectUsingReflection");

                
    for (int i = 0; i < 50000; i++)
                {
                    
    object content = DirectSerialize(pojo);
                }

                EndTest(
    "Begin CreateObjectUsingReflection");
            }


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

    Begin CreateObjectUsingReflection
    Begin CreateObjectUsingReflection
    00:00:04.5937500

    Begin CreateObjectUsingReflection
    Begin CreateObjectUsingReflection
    00:00:06.4531250

    Begin CreateObjectUsingReflection
    Begin CreateObjectUsingReflection
    00:00:00.9218750

    Begin CreateObjectUsingReflection
    Begin CreateObjectUsingReflection
    00:00:00.1406250


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

    提升比率是: 7倍!!!接近一个数量级了!!!只要再优化逻辑,那么就可以达到一个数量级的提升。

    顺便贴出EMIT的性能和反射比较:

    代码
    public void test005_1()
            {
                Person p 
    = new Person();
                p.Age 
    = 1;
                p.Name 
    = "123";
                p.Price 
    = 12;
                p.Type 
    = PersonType.A;


                StartTest(
    "start reflection");

                
    for (int i = 0; i < 100000; i++)
                {
                    ReflectionSerialize(p);
                }

                EndTest(
    "end reflection");


                StartTest(
    "start emit");

                DummyTypeSerializeHandler handler 
    = DummyMethodFactory.CreateDummySerializeHandler(p.GetType());

                
    for (int i = 0; i < 100000; i++)
                {
                    handler(p);
                }

                EndTest(
    "end emit");


                StartTest(
    "start emit");

                
    for (int i = 0; i < 100000; i++)
                {
                    ReflectionManager.CreateDummyType(p);
                }

                EndTest(
    "end emit");
            }
    代码
    ------ Test started: Assembly: Pixysoft.Framework.Reflection.dll ------

    start reflection
    end reflection
    00:00:04.2812500

    start emit
    end emit
    00:00:01.2343750 //内存直接调用

    start emit
    end emit
    00:00:01.5937500 //缓存调用


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

    性能比较是: 3.47倍!

    看来使用了自己的EMIT对象之后,性能提升了非常快! 

  • 相关阅读:
    侠客博客v1.0 正式版版本发布
    酒店分销赚钱
    备份VPS 每周同步文件
    关于伪原创编辑的技巧
    在线考试系统,按计划一点一点的开发。
    WORDPRESS”丢失计划任务”
    钦和SEO服务DLL
    ORM之MySoft_Data测试成功。应该是非常好用的。
    发送了50左右篇博客文章
    writeFlashHTML,一个JS方法,主要用于Flash的输出。
  • 原文地址:https://www.cnblogs.com/zc22/p/1750358.html
Copyright © 2011-2022 走看看