简单对比了一下MonoXml与SystemXml在Unity下的表现
2024-09-30 19:20:14
测试代码
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
最新文章
- Angular2 NgModule
- python 中date datetime time 与str的互转
- [转载]:Delphi xe7并行编程快速入门
- Log4net使用指南
- KS-检验(Kolmogorov-Smirnov test) -- 检验数据是否符合某种分布
- power tool 强制撤销
- jjjjQuery选择器
- CSS样式之选择器
- 在Jekyll博客添加评论系统:gitment篇
- Uva 548 二叉树的递归遍历lrj 白书p155
- JeeWx全新版本发布!捷微二代微信活动平台1.0发布!活动插件持续开源更新!
- Code First的实体继承模式
- 洗礼灵魂,修炼python(82)--全栈项目实战篇(10)—— 信用卡+商城项目(模拟京东淘宝)
- 01 响应式页面-@media介绍,
- SoapUI Pro Project Solution Collection-access the soapui object
- Apache Tika
- rhel7 ifconfig command not found
- rovio视觉里程计的笔记
- Linux一些基本命令一(学习笔记三)
- 第七章&#160;二叉搜索树 07B2-1 插入:算法
热门文章
- 什么是DO,DTO,VO,POJO
- Linux安装配置PHPmyadmin
- 02【Collection、泛型】
- 02-java实现单链表
- 08 vi全屏文本编辑器
- C#LeetCode刷题之#226-翻转二叉树(Invert Binary Tree)
- C#LeetCode刷题之#58-最后一个单词的长度(Length of Last Word)
- .Net 桌面程序(winform,wpf,跨平台avalonia)打安装包部署到windows 入门
- 浏览器自动化的一些体会7 selenium webdriver的一些问题
- AS 新安装Android Studio运行项目前报错:Unable to access Android SDK add-on list