为什么XmlTextReader在Unity中变得如此缓慢?

时间:2017-06-15 01:07:08

标签: c# xml unity3d large-files u3d

我需要解析一个大的XML文件(≈100MB,400000rows ),然后将数据放入List。

  • 首先,我尝试在 C#控制台应用程序中解析XML文件,然后使用 2s 来完成作业。
  • 然后我将代码复制到 Unity ,然后用 17s 来完成这项工作。

有人知道为什么会这么慢吗?以及如何让它更快? 谢谢!

代码:

// Used for storing data
stateList = new List<BallisticState>();
XmlTextReader reader = new XmlTextReader(filepath);
while (reader.Read())
{
    if (reader.NodeType == XmlNodeType.Element)
    {
        if (reader.Name == "row")
        {
            string value = reader.GetAttribute("value").TrimStart();

            BallisticState state = new BallisticState();
            // this method converts string to float
            SetBallisticState(state, value);

            stateList.Add(state);
        }
    }
}

0 个答案:

没有答案
相关问题