I am processing an XML file that has very slow performance when selecting Nodes with XPath style selectors.
Here is part of the code that runs particularily slow
for (i=0;i<lanes.length;i++)
htmlContents += GetLaneInfo($(this).find("Lane[num='"+lanes[i]+"']").attr('avg'));
I believe the slowest part of this code is the Lane[num=X]
selector, how can I improve the performance of this? Can I cache $(this).find("Lanes")
and then search through them later on?
XML Sample:
<Data time="10:50">
<Lane num="102" avg="2.0"/>
<Lane num="103" avg="2.0"/>
<Lane num="104" avg="2.0"/>
<Lane num="112" avg="2.0"/>
<Lane num="113" avg="2.0"/>
<Lane num="114" avg="2.0"/>
<Lane num="115" avg="2.0"/>
<Lane num="122" avg="0.9"/>
<Lane num="123" avg="1.0"/>
<Lane num="124" avg="1.0"/>
<Lane num="132" avg="0.7"/>
<Lane num="134" avg="0.7"/>
<Lane num="142" avg="0.8"/>
<Lane num="153" avg="0.4"/>
<Lane num="154" avg="0.6"/>
</Data>