简单对比了一下MonoXml与SystemXml在Unity下的表现
测试代码
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
简单对比了一下MonoXml与SystemXml在Unity下的表现的更多相关文章
- MongoDB中insert方法、update方法、save方法简单对比
MongoDB中insert方法.update方法.save方法简单对比 1.update方法 该方法用于更新数据,是对文档中的数据进行更新,改变则更新,没改变则不变. 2.insert方法 该方法用 ...
- .NET轻量级MVC框架:Nancy入门教程(二)——Nancy和MVC的简单对比
在上一篇的.NET轻量级MVC框架:Nancy入门教程(一)——初识Nancy中,简单介绍了Nancy,并写了一个Hello,world.看到大家的评论,都在问Nancy的优势在哪里?和微软的MVC比 ...
- HTTPS, SPDY和 HTTP/2性能的简单对比
中文原文:HTTPS, SPDY和 HTTP/2性能的简单对比 整理自:A Simple Performance Comparison of HTTPS, SPDY and HTTP/2 请尊重版权, ...
- 【转贴】Cortex系列M0-4简单对比
转载网址:http://blog.sina.com.cn/s/blog_7dbd9c0e01018e4l.html 最近搞了块ST的Cortex-M4处理器,然后下了本文档.分享一下. 针对目前进入大 ...
- 简单对比Spark和Storm
2013年参与开发了一个类似storm的自研系统, 2014年使用过spark 4个多月,对这两个系统都有一些了解. 下面是我关于这两个系统的简单对比: Spark: 1. 基于数据并行,https: ...
- Nancy和MVC的简单对比
Nancy和MVC的简单对比 在上一篇的.NET轻量级MVC框架:Nancy入门教程(一)——初识Nancy中,简单介绍了Nancy,并写了一个Hello,world.看到大家的评论,都在问Nancy ...
- [评测]低配环境下,PostgresQL和Mysql读写性能简单对比(欢迎大家提出Mysql优化意见)
[评测]低配环境下,PostgresQL和Mysql读写性能简单对比 原文链接:https://www.cnblogs.com/blog5277/p/10658426.html 原文作者:博客园--曲 ...
- 百度 OCR API 的使用以及与 Tesseract 的简单对比
目录 百度 OCR API 初探 用 Python 调用百度 OCR API 与 Tesseract 的简单对比 百度 OCR API 初探 近日得知百度在其 APIStore 上开放了 OCR 的 ...
- Rx与Async Task的简单对比
有关Reactive Extensions的介绍可见https://rx.codeplex.com/,总的来说,你可以当它是又一个异步编程的框架,它以观察者模式实现了对数据流的的“订阅”.一个列表,一 ...
随机推荐
- 【BZOJ4398】福慧双修 题解(建图优化)
题目链接 题目大意:给定一张$n$个点$m$条边的无向图,每条边两个方向的权值不一定相同.问从$1$出发不重复走一条边回到$1$的最短路径. ------------------- 暴力不太会.大概是 ...
- ios 淘宝评论详情、朋友圈布局masony实现
最近做项目,用到了类似于淘宝的朋友圈的功能,然后自己抽出了一个小demo,与大家分享 介绍:用的是masony布局的cell这样的话,文本,以及图片可以自适应,不用人工再去计算高度,很方便. 注:该d ...
- 618购物节要到了,Python帮你实现商品有货的微信提醒
时间过的真快,不知不觉一年已过了一半,又快到618购物狂欢节了,剁手党们都希望无论是618购物节还是双11购物节,都能够买到便宜又实惠的商品,但是真心实惠的东西往往是紧俏的,经常会出现无货的情况,我们 ...
- CSS漂亮盒子(上)
HTML文档中的所有元素都是由矩形盒子构成的--不管是包含页面结构的容器元素,还是段落中的每行文本,归根结底都是盒子. 1.背景颜色 设置页面背景颜色. body { background-color ...
- 2020-06-16:Redis hgetall时间复杂度?
福哥答案2020-06-16: 时间复杂度是O(N).时间复杂度:O(N) where N is the size of the hash.
- neo4j批量导入数据的两种解决方案
neo4j批量导入数据有两种方法,第一种是使用cypher语法中的LOAD CSV,第二种是使用neo4j自带的工具neo4j-admin import. LOAD CSV 导入的文件必须是csv文件 ...
- 怎么对比两个excel文档的数据差异
百度经验: https://jingyan.baidu.com/article/6181c3e0877c7a152ef15304.html
- Jmeter系列(50)- 详解 If 控制器
如果你想从头学习Jmeter,可以看看这个系列的文章哦 https://www.cnblogs.com/poloyy/category/1746599.html 简单介绍 可以通过条件来控制是否运行其 ...
- springboot + mybatisPlus 入门实例 入门demo
springboot + mybatisPlus 入门实例 入门demo 使用mybatisPlus的优势 集成mybatisplus后,简单的CRUD就不用写了,如果没有特别的sql,就可以不用ma ...
- [PyTorch 学习笔记] 1.4 计算图与动态图机制
本章代码:https://github.com/zhangxiann/PyTorch_Practice/blob/master/lesson1/computational_graph.py 计算图 深 ...