zoukankan      html  css  js  c++  java
  • 提醒一下:XmlSerializer的效率比BinaryFormatter高!

    从前的经验是:二进制文件的读写效率比文本的高,不要说还要解析xml结构啥的。

    于是,前几天需要暂存内存里百万条左右的数据时,毫不迟疑地选择了BinaryFormatter.

    每次重新读回内存都要N长时间。

    最后一次,为了方便人工查看,改了一下用了 XmlSerializer来保存数据,人工查看处理完之后,再加载到内存里,突然感觉怎么这么快!

    于是找时间做了个测试,发现自己杯具了,知识更新太慢,不知道原来xml的效率已经超过bin了!

    下面是对比:

    XmlSerializer

    BinaryFormatter

    59,031 ms

    117,763 ms

    61,925 ms

    64,565 ms

    文件容量

    794,067,056 byte

    314,505,339 byte

     但是文件大小xml是bin的2.5倍。 但是我看了生成的文件内容,确认binaryformatter并没有采用压缩算法。

    即然硬盘空间不是问题,以后就xml吧。

     ---------------------------------------------------

    测试程序很简单:

    xml保存: 

     xml保存


    xml加载数据 :

    xml加载数据
    XmlSerializer formatter = new XmlSerializer(typeof(ArrayList),
    new Type[]
    {
     
    typeof(App_risk), typeof(Appnext), typeof(Chagapp),
     
    typeof(Chgcon), typeof(Ch_apid), typeof(Ch_enno),
     
    typeof(Ch_handno), typeof(Ch_id), typeof(Ch_insno),
     
    typeof(Ch_pono), typeof(Ch_p_handno), typeof(Ch_txhand),
     
    typeof(Comcust), typeof(Custmatl), typeof(Hxbtest),
     
    typeof(Modify), typeof(Nclmccl), typeof(Nmodclaim),
     
    typeof(Nregclm), typeof(Prerec), typeof(Relpayrc),
     
    typeof(Riskcon), typeof(Tmprec), typeof(Riskspec)
    }
    );
    ArrayList al 
    = (ArrayList)formatter.Deserialize(fs);

    bin保存数据: 

    BinaryFormatter formatter = new BinaryFormatter();
    formatter.Serialize(fs, (ArrayList)
    this.htTargetTables[sTabName]);

    BIN加载数据:
    BinaryFormatter formatter = new BinaryFormatter();
    ArrayList al 
    = (ArrayList)formatter.Deserialize(fs);
  • 相关阅读:
    Oracle ——优化内存
    用 C# 实现 HTTP 协议多线程下载文件
    Oracle 为表某个字段进行字母数字组合编码
    Oracle 11g Release 1 (11.1)——自动存储管理(Automatic Storage Management,ASM)
    Oracle 11g Release 1 (11.1) Oracle Text 如何创建 CTXCAT 索引
    Oracle ——如何确定性能差的 SQL
    MySQL 5.5/5.6——概述 MySQL 客户端程序
    Oracle 数据库统计信息描述
    Oracle Database Instant Client
    HTTP 协议演示——HTTP 协议(45)
  • 原文地址:https://www.cnblogs.com/haoxiaobo/p/1913103.html
Copyright © 2011-2022 走看看