测试代码

public class NewBehaviourScript : MonoBehaviour {

    // Use this for initialization
void Start () { } static void TestXmlLoad(string xml)
{
SecurityParser parser = new SecurityParser();
parser.LoadXml(xml);
} static void TestSystemXMLLoad(string xml)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
} int count = ; // Update is called once per frame
void Update () {
if(++count == )
{
string xmlText = File.ReadAllText(@"F:\Projects\TestPXML\TestPXML\test.xml"); int LoadCount = ; Stopwatch stopwatch = new Stopwatch();
{
stopwatch.Start(); for (int i = ; i < LoadCount; ++i)
{
TestXmlLoad(xmlText);
} UnityEngine.Debug.Log(string.Format("MonoXml Load:{0}", stopwatch.Elapsed));
} {
stopwatch.Stop();
stopwatch.Start(); for (int i = ; i < LoadCount; ++i)
{
TestSystemXMLLoad(xmlText);
} UnityEngine.Debug.Log(string.Format("SystemXml Load:{0}", stopwatch.Elapsed));
}
}
}
}

测试用xml400kb左右。

时间:

看起来MonoXml会快一点,大约少1/3左右的时间开销。

内存:

开了DeepProfile。看起来Systemxml需要更少的内存,不开DeepProfile测不到内存,这就尴尬了。

另外在非Unity环境下测试了一下,使用代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Mono.Xml;
using System.Diagnostics; namespace TestPXML
{
class Program
{
private static List<object> Caches = new List<object>(); static void Main(string[] args)
{
// Console.WriteLine("prepare load from monoxml");
// Console.ReadKey(); string xmlText = Encoding.UTF8.GetString(Properties.Resources.SettlementForm); int LoadCount = ; GC.Collect();
GC.Collect(); Stopwatch stopwatch = new Stopwatch();
// {
// stopwatch.Start();
//
// for(int i=0; i<LoadCount; ++i)
// {
// TestXmlLoad(xmlText);
// }
//
// Console.WriteLine($"MonoXml Load:{stopwatch.Elapsed}");
// } Console.WriteLine("prepare load from system.xml");
Console.ReadKey();
{
stopwatch.Stop();
stopwatch.Start(); for (int i = ; i < LoadCount; ++i)
{
TestSystemXMLLoad(xmlText);
} Console.WriteLine($"SystemXML Load:{stopwatch.Elapsed}");
} GC.Collect();
GC.Collect(); Console.WriteLine("all done, press any key.");
Console.ReadKey();
} static void TestXmlLoad(string xml)
{
SecurityParser parser = new SecurityParser();
parser.LoadXml(xml); Caches.Add(parser);
} static void TestSystemXMLLoad(string xml)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml); Caches.Add(doc);
}
}
}

   为了避免误差,cache之类的,使用工具分两个波次测试。

SystemXML结论如下:

MonoXML结论如下:

因此基本可以证明,MonoXml加载速度比SystemXml快,但是需要的内存开销会高于System.xml

最新文章

  1. Angular2 NgModule
  2. python 中date datetime time 与str的互转
  3. [转载]:Delphi xe7并行编程快速入门
  4. Log4net使用指南
  5. KS-检验(Kolmogorov-Smirnov test) -- 检验数据是否符合某种分布
  6. power tool 强制撤销
  7. jjjjQuery选择器
  8. CSS样式之选择器
  9. 在Jekyll博客添加评论系统:gitment篇
  10. Uva 548 二叉树的递归遍历lrj 白书p155
  11. JeeWx全新版本发布!捷微二代微信活动平台1.0发布!活动插件持续开源更新!
  12. Code First的实体继承模式
  13. 洗礼灵魂,修炼python(82)--全栈项目实战篇(10)—— 信用卡+商城项目(模拟京东淘宝)
  14. 01 响应式页面-@media介绍,
  15. SoapUI Pro Project Solution Collection-access the soapui object
  16. Apache Tika
  17. rhel7 ifconfig command not found
  18. rovio视觉里程计的笔记
  19. Linux一些基本命令一(学习笔记三)
  20. 第七章&#160;二叉搜索树 07B2-1 插入:算法

热门文章

  1. 什么是DO,DTO,VO,POJO
  2. Linux安装配置PHPmyadmin
  3. 02【Collection、泛型】
  4. 02-java实现单链表
  5. 08 vi全屏文本编辑器
  6. C#LeetCode刷题之#226-翻转二叉树(Invert Binary Tree)
  7. C#LeetCode刷题之#58-最后一个单词的长度(Length of Last Word)
  8. .Net 桌面程序(winform,wpf,跨平台avalonia)打安装包部署到windows 入门
  9. 浏览器自动化的一些体会7 selenium webdriver的一些问题
  10. AS 新安装Android Studio运行项目前报错:Unable to access Android SDK add-on list