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.