测试代码

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下的表现的更多相关文章

  1. MongoDB中insert方法、update方法、save方法简单对比

    MongoDB中insert方法.update方法.save方法简单对比 1.update方法 该方法用于更新数据,是对文档中的数据进行更新,改变则更新,没改变则不变. 2.insert方法 该方法用 ...

  2. .NET轻量级MVC框架:Nancy入门教程(二)——Nancy和MVC的简单对比

    在上一篇的.NET轻量级MVC框架:Nancy入门教程(一)——初识Nancy中,简单介绍了Nancy,并写了一个Hello,world.看到大家的评论,都在问Nancy的优势在哪里?和微软的MVC比 ...

  3. HTTPS, SPDY和 HTTP/2性能的简单对比

    中文原文:HTTPS, SPDY和 HTTP/2性能的简单对比 整理自:A Simple Performance Comparison of HTTPS, SPDY and HTTP/2 请尊重版权, ...

  4. 【转贴】Cortex系列M0-4简单对比

    转载网址:http://blog.sina.com.cn/s/blog_7dbd9c0e01018e4l.html 最近搞了块ST的Cortex-M4处理器,然后下了本文档.分享一下. 针对目前进入大 ...

  5. 简单对比Spark和Storm

    2013年参与开发了一个类似storm的自研系统, 2014年使用过spark 4个多月,对这两个系统都有一些了解. 下面是我关于这两个系统的简单对比: Spark: 1. 基于数据并行,https: ...

  6. Nancy和MVC的简单对比

    Nancy和MVC的简单对比 在上一篇的.NET轻量级MVC框架:Nancy入门教程(一)——初识Nancy中,简单介绍了Nancy,并写了一个Hello,world.看到大家的评论,都在问Nancy ...

  7. [评测]低配环境下,PostgresQL和Mysql读写性能简单对比(欢迎大家提出Mysql优化意见)

    [评测]低配环境下,PostgresQL和Mysql读写性能简单对比 原文链接:https://www.cnblogs.com/blog5277/p/10658426.html 原文作者:博客园--曲 ...

  8. 百度 OCR API 的使用以及与 Tesseract 的简单对比

    目录 百度 OCR API 初探 用 Python 调用百度 OCR API 与 Tesseract 的简单对比 百度 OCR API 初探 近日得知百度在其 APIStore 上开放了 OCR 的 ...

  9. Rx与Async Task的简单对比

    有关Reactive Extensions的介绍可见https://rx.codeplex.com/,总的来说,你可以当它是又一个异步编程的框架,它以观察者模式实现了对数据流的的“订阅”.一个列表,一 ...

随机推荐

  1. 服务消费者(RestTemplate+Ribbon+feign)

    负载均衡 ​ spring cloud 体系中,我们知道服务之间的调用是通过http协议进行调用的.注册中心就是维护这些调用的服务的各个服务列表.在Spring中提供了RestTemplate,用于访 ...

  2. 使用Flask开发简单接口(4)--借助Redis实现token验证

    前言 在之前我们已开发了几个接口,并且可以正常使用,那么今天我们将继续完善一下.我们注意到之前的接口,都是不需要进行任何验证就可以使用的,其实我们可以使用 token ,比如设置在修改或删除用户信息的 ...

  3. MapReduce之自定义OutputFormat

    @ 目录 OutputFormat接口实现类 自定义OutputFormat使用场景及步骤 使用场景 自定义OutputFormat 案例实操 OutputFormat接口实现类 OutputForm ...

  4. Hive: Reflect UDF

    Reflect UDF JAVA类和方法通常用于处理用户希望在hive中使用的确切的函数.相比与封装一个UDF然后调用这个方法,这些 方法主要通过反射UDF去调用.Reflect使用Java反射去实例 ...

  5. CSS学习第三天

    定位布局: 相对定位:相对于自身的位置进行偏移position需要搭配left right top bottom      position: relative; 绝对定位:相对于有position属 ...

  6. C#LeetCode刷题-深度优先搜索

    深度优先搜索篇 # 题名 刷题 通过率 难度 98 验证二叉搜索树   22.2% 中等 99 恢复二叉搜索树   45.1% 困难 100 相同的树   48.1% 简单 101 对称二叉树   4 ...

  7. Vuex mapMutation的基本使用

    mapMutation-store中的同步方法 import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) export default n ...

  8. Flutter 容器(8) - SizedOverflowBox | OverflowBox

    SizedOverflowBox: 子组件在超出SizedOverflowBox指定的宽高时,不会隐藏,依然进行绘制 OverflowBox: 限制子组件的宽高. import 'package:fl ...

  9. Umlet和draw.io 使用心得

    文章目录 软件使用心得 1. Umlet 画图软件 1.1 前言 1.2 优点 1.3使用小trick 1.3.1 灵活改变箭头形式 1.3.2 整体复制 1.3.3 快速复制 2. draw.io ...

  10. 洛谷P1579.验证哥德巴赫猜想(DFS+素性测试)

    题目背景 1742年6月7日哥德巴赫写信给当时的大数学家欧拉,正式提出了以下的猜想:任何一个大于9的奇数都可以表示成3个质数之和.质数是指除了1和本身之外没有其他约数的数,如2和11都是质数,而6不是 ...