0

I need to parse a big XML file (≈100MB, 400000rows) then put the data in a List.

  • First I try to parse the XML file in a C# console application, it taked about 2s to finish the job.
  • Then I copy the code into Unity, and it taked about 17s to finish the job.

Anybody know why it become so slowly? And how to make it faster? Thanks!

Code:

// 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);
        }
    }
}
Qiuyu ZHANG
  • 991
  • 1
  • 7
  • 9
  • We don't have access to your XML file here so you have to help us determine which part of your code is really slow. Maybe it is `new XmlTextReader(filepath);`, `reader.Read()` or the code inside the `while` loop. Please [time](https://stackoverflow.com/a/16376203/3785314) these three stuff I mentioned in both Console and Unity app then update your question with the result of each one. It would be good to post your timing code too so that we know you are doing it right. – Programmer Jun 15 '17 at 01:31
  • 1
    Is XML the correct structure for your data? – Quality Catalyst Jun 15 '17 at 01:43

0 Answers0