Jump to content

Speed question


Gwendalin

Recommended Posts

Why does assigning this variable significantly slow my program down? If i have the name = cloneinfo.element line commented out the program completes in under a minute. When i enable the line it takes like 2 - minutes to complete. Shouldn't the value be read into memory already when it is assigned to clone info? i'm just reassigning it to a different variable name.

 

var cloneInfo = lbXML
                    .Descendants("Game")
                    .Where(x => (string)x.Element("ID").Value == element.Element("GameID").Value)
                    .Select(x => (x.Element("Title").Value));

 

name = cloneInfo.ElementAt(0);

Link to comment
Share on other sites

Try adding .ToArray() after your select.

You've created a sequence of commands that gets executed each time it tries to find data in it, rather than creating an array/list to search through.

(Linq is funny like that, if you don't execute it to finalize it yourself it does to every time you request data from it)

Link to comment
Share on other sites

Thanks Joyce... unfortunately it is still slow when assigning name.

 

var cloneInfo = lbXML
                    .Descendants("Game")
                    .Where(x => (string)x.Element("ID").Value == element.Element("GameID").Value)
                    .Select(x => (x.Element("Title").Value)).ToArray();
               

name = cloneInfo.First();

Link to comment
Share on other sites

yeah,

 

This takes about 30 seconds

var cloneInfo = lbXML
                    .Descendants("Game")
                    .Where(x => (string)x.Element("ID").Value == element.Element("GameID").Value)
                    .Select(x => (x.Element("Title").Value)).ToArray();
               

//name = cloneInfo.First();

 

------------------------------------------------------------------------------------------------------------------------------

 

this takes about 3 minutes

var cloneInfo = lbXML
                    .Descendants("Game")
                    .Where(x => (string)x.Element("ID").Value == element.Element("GameID").Value)
                    .Select(x => (x.Element("Title").Value)).ToArray();
               

name = cloneInfo.First();

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...