Thread: Which one is "quicker" ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User AloneInTheDark's Avatar
    Join Date
    Feb 2008
    Posts
    74

    Which one is "quicker", using a string or SelectSingleNode? ?

    I need to use some field "ID" a couple of times in loop, say for example 4 times in a loop, which one of these code would be faster ?

    Code:
    foreach(XmlNode XMLNODE in XML_menu.SelectSingleNode("menu").ChildNodes){
    Console.WriteLine( XMLNODE.SelectSingleNode("@id").InnerText );
    Console.WriteLine( XMLNODE.SelectSingleNode("@id").InnerText );
    Console.WriteLine( XMLNODE.SelectSingleNode("@id").InnerText );
    Console.WriteLine( XMLNODE.SelectSingleNode("@id").InnerText );
    }
    or

    Code:
    foreach(XmlNode XMLNODE in XML_menu.SelectSingleNode("menu").ChildNodes){
    string ID = XMLNODE.SelectSingleNode("@id").InnerText;
    Console.WriteLine( ID );
    Console.WriteLine( ID );
    Console.WriteLine( ID );
    Console.WriteLine( ID );
    }
    What I mean is, is it faster to you "XMLNODE.SelectSingleNode" many times or should I first get its value into some string and then use that string many times?
    Last edited by AloneInTheDark; 02-08-2008 at 07:41 PM. Reason: Altered the title.

Popular pages Recent additions subscribe to a feed