Click here to Skip to main content
15,886,095 members
Articles / Desktop Programming / WTL
Article

XML timing

Rate me:
Please Sign up or sign in to vote.
1.58/5 (7 votes)
3 Nov 2001CPOL2 min read 64.1K   985   10   5
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)



Comments and Discussions

 
GeneralXMLTable hint Pin
Anonymous6-Apr-05 5:55
Anonymous6-Apr-05 5:55 
GeneralRe: XMLTable hint Pin
Not Active6-Apr-05 8:49
mentorNot Active6-Apr-05 8:49 
QuestionWhat about some results? Pin
beetung27-Nov-02 14:24
beetung27-Nov-02 14:24 
AnswerRe: What about some results? Pin
Thomas Lykke Petersen14-Jun-04 21:57
Thomas Lykke Petersen14-Jun-04 21:57 
GeneralRe: What about some results? Pin
Joseph Ellsworth20-Dec-04 15:36
Joseph Ellsworth20-Dec-04 15:36 

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

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