简单对比了一下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/,总的来说,你可以当它是又一个异步编程的框架,它以观察者模式实现了对数据流的的“订阅”.一个列表,一 ...
随机推荐
- 关于welcom-file-list 失效
遇到个很奇怪的问题: 在使用shrio的时候,未登陆的情况下,能正常识别转发welcome-file-list index 登陆之后无法识别welcom-file-list,需要手动输入/ind ...
- Eclipse RCP:多平台部署
1 问题 在使用Eclipse RCP IDE进行开发时,它自带的PDE(插件开发环境)工具仅能够导出相同平台的部署包,比如win32的仅能导出win32的,linux64仅能够导出linux64的. ...
- ACL2020 Contextual Embeddings When Are They Worth It 精读
上下文嵌入(Bert词向量): 什么时候值得用? ACL 2018 预训练词向量 (上下文嵌入Bert,上下文无关嵌入Glove, 随机)详细分析文章 1 背景 图1 Bert 优点 效果显著 缺点 ...
- PyTorch 学习
PyTorch torch.autograd模块 深度学习的算法本质上是通过反向传播求导数, PyTorch的autograd模块实现了此功能, 在Tensor上的所有操作, autograd都会为它 ...
- gym102586 部分题解
目录 Evacuation Sum Modulo Count Modulo 2 Robots Construct Points Amidakuji Yosupo's Algorithm link 出于 ...
- 【LeetCode/LintCode】 题解丨字节跳动试题:第k大的子数组
给定一个长度为n的数组a,它有n(n+1)/2个子数组.请计算这些子数组的和,然后按照升序排列,并返回排序后第k个数. 1≤n≤10^5 1≤ai≤10^9 1≤k≤n(n+1)/2 在线 ...
- JavaScript String.prototype 原型
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...
- C#LeetCode刷题之#671-二叉树中第二小的节点(Second Minimum Node In a Binary Tree)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4100 访问. 给定一个非空特殊的二叉树,每个节点都是正数,并且每 ...
- 在eclipse中搜索 datasource.xml 文件:
- 校内测试:T1秋末的落叶(命题人gxl)官方题解
秋末的落叶 题解 传送门:https://www.luogu.com.cn/problem/U121886 Part 1:疏通题意 首先,我们从题意和样例解释中很容易提取到以下信息: \(1.\)本题 ...