Click here to Skip to main content
Licence CPOL
First Posted 3 Nov 2001
Views 53,080
Bookmarked 10 times

XML timing

By | 3 Nov 2001 | Article
Test timing of searching using an XML document or a simple array of structures.

Sample Image - XMLTiming.jpg

Introduction

While designing an application, the team decided on using XML to store and read configuration data needed to start the application. It was also decided to use the same document to store runtime data. Since the XML document would already be in memory and because the application would also need the data stored within it to lookup and insert new elements, this seemed like a good choice. Then someone asked the question, “What about speed?” Would the XML method produce any benefit in lookup times over using a simple array of structures?

I can’t recall seeing any data or applications that could answer this question, so I put together a quick application to perform some timing tests and get the data to answer this question, at least in our particular situation. It may not apply to all projects but it may give answers to others with similar questions.

The config_data.xml file included with the sample code is what is produced after the configuration document has been loaded and the runtime information is inserted. I read the tag elements from this and populated an array of structures that have a similar makeup.

<tag id="1" name="Cmd" datatype="INT" type="CMD" bit="-1" 
          client_id="3" server_id="15067272" value="0"/>

typedef struct tagTESTDATA 
{ 
  int nID; 
  TCHAR szName[10]; 
  short sDataType; 
  ALARM_TYPES eType; 
  short sBit; 
  long lClient; 
  long lServer; 
  TCHAR szValue[4]; 
} TESTDATA;

The two list boxes on the dialog are populated with IDs that are used to perform the lookups against. Rather than just selecting random IDs, I allow the user to select, so the test would not be skewed and multiple combinations on array positions could be tested. The timing for the XML uses a selectSingleNode with XPath notation. While the array uses a for loop to evaluate each structure in the array until a match is found.

CComPtr<IXMLDOMNode> pNode = NULL; 
if( SUCCEEDED(m_pDoc->selectSingleNode(strParam.AllocSysString(), 
                                                &pNode)) && pNode) 

for(long x = 0; x < m_nCount; x++ ) 
{ 
  if( m_data[x].lClient == lVal ) 
    break; 
}

Each test performed 5 times and the average is returned.

Caution: You need MSXML 4.0 for this application.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Mark Nischalke



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralXMLTable hint PinsussAnonymous5:55 6 Apr '05  
GeneralRe: XMLTable hint PinmemberMark Nischalke8:49 6 Apr '05  
QuestionWhat about some results? Pinmemberbeetung14:24 27 Nov '02  
AnswerRe: What about some results? Pinmembersinus-c21:57 14 Jun '04  
GeneralRe: What about some results? PinmemberJoseph Ellsworth15:36 20 Dec '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 4 Nov 2001
Article Copyright 2001 by Mark Nischalke
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid