Node vs Double select (faster without jQuery)

JavaScript performance comparison

Revision 13 of this test case created by François Gannaz

Info

As of jQuery 1.8, there is not XML selector that works with namespaces. Instead of the custom plugin hack introduced by this series of tests, this test illustrates an alternative with a DOM2 method. It should work in any recent browser and it is much faster.

This test only uses the most recent version of jQuery.

Side note:the third test will output wrong results depending on the XML input. For instance, if the tags "z:row" and "a:row" exists, they will both get selected.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    jQuery.fn.filterNode = function(name) {
      return this.filter(function() {
        return this.nodeName === name;
      });
    };
   
    var xData = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body<GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult<listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"><rs:data ItemCount="8"><z:row ows_ContentTypeId="0x0100DDB33E0A25E44140B53A905E8CD2C111" ows_Title="One" ows_DisplayName="One" ows_ID="1" ows_ContentType="Item" ows_Modified="2011-03-17 10:31:28" ows_Created="2010-06-14 15:20:20" ows_Author="462;#Workman, Steve" ows_Editor="363;#Keech, Victor" ows_owshiddenversion="7" ows_WorkflowVersion="1" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="One" ows_LinkTitle="One" ows_SelectTitle="1" ows_Order="100.000000000000" ows_GUID="{37E1EF7B-7DCC-4390-87C4-FAF4315E3F5B}" ows_FileRef="1;#pdm/Lists/Segments/1_.000" ows_FileDirRef="1;#pdm/Lists/Segments" ows_Last_x0020_Modified="1;#2010-12-07 06:10:02" ows_Created_x0020_Date="1;#2010-12-07 06:10:02" ows_FSObjType="1;#0" ows_PermMask="0x7fffffffffffffff" ows_FileLeafRef="1;#1_.000" ows_UniqueId="1;#{CDB32DA8-BCD6-4F0D-A972-961AD1A3F2B5}" ows_ProgId="1;#" ows_ScopeId="1;#{0A8885B3-92F5-4F6B-A7E1-58FB7543BEB6}" ows__EditMenuTableStart="1_.000" ows__EditMenuTableEnd="1" ows_LinkFilenameNoMenu="1_.000" ows_LinkFilename="1_.000" ows_ServerUrl="/pdm/Lists/Segments/1_.000" ows_EncodedAbsUrl="http://example.com/pdm/Lists/Segments/1_.000" ows_BaseName="1_" ows_MetaInfo="1;#" ows__Level="1" ows__IsCurrentVersion="1" /><z:row ows_ContentTypeId="0x0100DDB33E0A25E44140B53A905E8CD2C111" ows_Title="Two" ows_DisplayName="Two" ows_ID="2" ows_ContentType="Item" ows_Modified="2010-06-14 15:20:31" ows_Created="2010-06-14 15:20:31" ows_Author="462;#Workman, Steve" ows_Editor="462;#Workman, Steve" ows_owshiddenversion="1" ows_WorkflowVersion="1" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Two" ows_LinkTitle="Two" ows_SelectTitle="2" ows_Order="200.000000000000" ows_GUID="{66F6BE42-BF5C-42C9-A8CE-4AE1E1644E20}" ows_FileRef="2;#pdm/Lists/Segments/2_.000" ows_FileDirRef="2;#pdm/Lists/Segments" ows_Last_x0020_Modified="2;#2010-12-07 06:10:06" ows_Created_x0020_Date="2;#2010-12-07 06:10:06" ows_FSObjType="2;#0" ows_PermMask="0x7fffffffffffffff" ows_FileLeafRef="2;#2_.000" ows_UniqueId="2;#{9EE493FF-D17B-473C-BAB8-B74E381615D6}" ows_ProgId="2;#" ows_ScopeId="2;#{0A8885B3-92F5-4F6B-A7E1-58FB7543BEB6}" ows__EditMenuTableStart="2_.000" ows__EditMenuTableEnd="2" ows_LinkFilenameNoMenu="2_.000" ows_LinkFilename="2_.000" ows_ServerUrl="/pdm/Lists/Segments/2_.000" ows_EncodedAbsUrl="http://example.com/pdm/Lists/Segments/2_.000" ows_BaseName="2_" ows_MetaInfo="2;#" ows__Level="1" ows__IsCurrentVersion="1" /><z:row ows_ContentTypeId="0x0100DDB33E0A25E44140B53A905E8CD2C111" ows_Title="Three" ows_DisplayName="Three" ows_ID="3" ows_ContentType="Item" ows_Modified="2010-06-14 15:20:41" ows_Created="2010-06-14 15:20:41" ows_Author="462;#Workman, Steve" ows_Editor="462;#Workman, Steve" ows_owshiddenversion="1" ows_WorkflowVersion="1" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Three" ows_LinkTitle="Three" ows_SelectTitle="3" ows_Order="300.000000000000" ows_GUID="{A5879457-3698-4A95-8A5C-B23E831D2D9D}" ows_FileRef="3;#pdm/Lists/Segments/3_.000" ows_FileDirRef="3;#pdm/Lists/Segments" ows_Last_x0020_Modified="3;#2010-12-07 06:10:07" ows_Created_x0020_Date="3;#2010-12-07 06:10:07" ows_FSObjType="3;#0" ows_PermMask="0x7fffffffffffffff" ows_FileLeafRef="3;#3_.000" ows_UniqueId="3;#{FAD5ED00-A0E6-4A4B-8F63-4580BB557575}" ows_ProgId="3;#" ows_ScopeId="3;#{0A8885B3-92F5-4F6B-A7E1-58FB7543BEB6}" ows__EditMenuTableStart="3_.000" ows__EditMenuTableEnd="3" ows_LinkFilenameNoMenu="3_.000" ows_LinkFilename="3_.000" ows_ServerUrl="/pdm/Lists/Segments/3_.000" ows_EncodedAbsUrl="http://example.com/pdm/Lists/Segments/3_.000" ows_BaseName="3_" ows_MetaInfo="3;#" ows__Level="1" ows__IsCurrentVersion="1" /><z:row ows_ContentTypeId="0x0100DDB33E0A25E44140B53A905E8CD2C111" ows_Title="Four" ows_DisplayName="Four" ows_ID="4" ows_ContentType="Item" ows_Modified="2010-09-09 13:49:47" ows_Created="2010-06-14 15:20:53" ows_Author="462;#Workman, Steve" ows_Editor="363;#Keech, Victor" ows_owshiddenversion="1" ows_WorkflowVersion="1" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Four" ows_LinkTitle="Four" ows_SelectTitle="4" ows_Order="400.000000000000" ows_GUID="{A874E89D-7CD6-4E87-BE6E-C392A1281576}" ows_FileRef="4;#pdm/Lists/Segments/4_.000" ows_FileDirRef="4;#pdm/Lists/Segments" ows_Last_x0020_Modified="4;#2010-12-07 06:10:08" ows_Created_x0020_Date="4;#2010-12-07 06:10:08" ows_FSObjType="4;#0" ows_PermMask="0x7fffffffffffffff" ows_FileLeafRef="4;#4_.000" ows_UniqueId="4;#{33D13964-274C-400F-9685-F47255393238}" ows_ProgId="4;#" ows_ScopeId="4;#{0A8885B3-92F5-4F6B-A7E1-58FB7543BEB6}" ows__EditMenuTableStart="4_.000" ows__EditMenuTableEnd="4" ows_LinkFilenameNoMenu="4_.000" ows_LinkFilename="4_.000" ows_ServerUrl="/pdm/Lists/Segments/4_.000" ows_EncodedAbsUrl="http://example.com/pdm/Lists/Segments/4_.000" ows_BaseName="4_" ows_MetaInfo="4;#" ows__Level="1" ows__IsCurrentVersion="1" /><z:row ows_ContentTypeId="0x0100DDB33E0A25E44140B53A905E8CD2C111" ows_Title="Five" ows_DisplayName="Five" ows_ID="5" ows_ContentType="Item" ows_Modified="2010-06-14 15:21:08" ows_Created="2010-06-14 15:21:08" ows_Author="462;#Workman, Steve" ows_Editor="462;#Workman, Steve" ows_owshiddenversion="1" ows_WorkflowVersion="1" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Five" ows_LinkTitle="Five" ows_SelectTitle="5" ows_Order="500.000000000000" ows_GUID="{406018AE-EF0F-4789-B3F2-FDC09C0D17D3}" ows_FileRef="5;#pdm/Lists/Segments/5_.000" ows_FileDirRef="5;#pdm/Lists/Segments" ows_Last_x0020_Modified="5;#2010-12-07 06:10:09" ows_Created_x0020_Date="5;#2010-12-07 06:10:09" ows_FSObjType="5;#0" ows_PermMask="0x7fffffffffffffff" ows_FileLeafRef="5;#5_.000" ows_UniqueId="5;#{13573117-A528-46E0-BE9B-A066CC14A8DE}" ows_ProgId="5;#" ows_ScopeId="5;#{0A8885B3-92F5-4F6B-A7E1-58FB7543BEB6}" ows__EditMenuTableStart="5_.000" ows__EditMenuTableEnd="5" ows_LinkFilenameNoMenu="5_.000" ows_LinkFilename="5_.000" ows_ServerUrl="/pdm/Lists/Segments/5_.000" ows_EncodedAbsUrl="http://example.com/pdm/Lists/Segments/5_.000" ows_BaseName="5_" ows_MetaInfo="5;#" ows__Level="1" ows__IsCurrentVersion="1" /><z:row ows_ContentTypeId="0x0100DDB33E0A25E44140B53A905E8CD2C111" ows_Title="Six" ows_DisplayName="Six" ows_ID="6" ows_ContentType="Item" ows_Modified="2010-06-14 15:21:21" ows_Created="2010-06-14 15:21:21" ows_Author="462;#Workman, Steve" ows_Editor="462;#Workman, Steve" ows_owshiddenversion="1" ows_WorkflowVersion="1" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Six" ows_LinkTitle="Six" ows_SelectTitle="6" ows_Order="600.000000000000" ows_GUID="{7C22C33A-8ECC-41B8-9D3E-DAA3DF02DE19}" ows_FileRef="6;#pdm/Lists/Segments/6_.000" ows_FileDirRef="6;#pdm/Lists/Segments" ows_Last_x0020_Modified="6;#2010-12-07 06:10:12" ows_Created_x0020_Date="6;#2010-12-07 06:10:12" ows_FSObjType="6;#0" ows_PermMask="0x7fffffffffffffff" ows_FileLeafRef="6;#6_.000" ows_UniqueId="6;#{35C0E27B-8F11-47E2-84B9-3074864AA91E}" ows_ProgId="6;#" ows_ScopeId="6;#{0A8885B3-92F5-4F6B-A7E1-58FB7543BEB6}" ows__EditMenuTableStart="6_.000" ows__EditMenuTableEnd="6" ows_LinkFilenameNoMenu="6_.000" ows_LinkFilename="6_.000" ows_ServerUrl="/pdm/Lists/Segments/6_.000" ows_EncodedAbsUrl="http://example.com/pdm/Lists/Segments/6_.000" ows_BaseName="6_" ows_MetaInfo="6;#" ows__Level="1" ows__IsCurrentVersion="1" /><z:row ows_ContentTypeId="0x0100DDB33E0A25E44140B53A905E8CD2C111" ows_Title="Seven" ows_DisplayName="Seven" ows_ID="7" ows_ContentType="Item" ows_Modified="2010-06-25 13:48:18" ows_Created="2010-06-25 13:48:18" ows_Author="462;#Workman, Steve" ows_Editor="462;#Workman, Steve" ows_owshiddenversion="1" ows_WorkflowVersion="1" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Seven" ows_LinkTitle="Seven" ows_SelectTitle="7" ows_Order="700.000000000000" ows_GUID="{015566E8-B432-460E-911F-3325BF9EC6ED}" ows_FileRef="7;#pdm/Lists/Segments/7_.000" ows_FileDirRef="7;#pdm/Lists/Segments" ows_Last_x0020_Modified="7;#2010-12-07 06:10:22" ows_Created_x0020_Date="7;#2010-12-07 06:10:22" ows_FSObjType="7;#0" ows_PermMask="0x7fffffffffffffff" ows_FileLeafRef="7;#7_.000" ows_UniqueId="7;#{2FFD2B33-92EF-4181-9A7C-5E6D96D90E26}" ows_ProgId="7;#" ows_ScopeId="7;#{0A8885B3-92F5-4F6B-A7E1-58FB7543BEB6}" ows__EditMenuTableStart="7_.000" ows__EditMenuTableEnd="7" ows_LinkFilenameNoMenu="7_.000" ows_LinkFilename="7_.000" ows_ServerUrl="/pdm/Lists/Segments/7_.000" ows_EncodedAbsUrl="http://example.com/pdm/Lists/Segments/7_.000" ows_BaseName="7_" ows_MetaInfo="7;#" ows__Level="1" ows__IsCurrentVersion="1" /><z:row ows_ContentTypeId="0x0100DDB33E0A25E44140B53A905E8CD2C111" ows_Title="Eight" ows_DisplayName="Eight" ows_ID="8" ows_ContentType="Item" ows_Modified="2010-06-28 16:54:40" ows_Created="2010-06-28 16:54:40" ows_Author="462;#Workman, Steve" ows_Editor="462;#Workman, Steve" ows_owshiddenversion="1" ows_WorkflowVersion="1" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Eight" ows_LinkTitle="Eight" ows_SelectTitle="8" ows_Order="800.000000000000" ows_GUID="{FEEBEFAC-3FC6-4F92-A03E-5202F3FB7295}" ows_FileRef="8;#pdm/Lists/Segments/8_.000" ows_FileDirRef="8;#pdm/Lists/Segments" ows_Last_x0020_Modified="8;#2010-12-07 06:10:22" ows_Created_x0020_Date="8;#2010-12-07 06:10:22" ows_FSObjType="8;#0" ows_PermMask="0x7fffffffffffffff" ows_FileLeafRef="8;#8_.000" ows_UniqueId="8;#{2D5EB204-7915-46E8-AC46-569B607F732D}" ows_ProgId="8;#" ows_ScopeId="8;#{0A8885B3-92F5-4F6B-A7E1-58FB7543BEB6}" ows__EditMenuTableStart="8_.000" ows__EditMenuTableEnd="8" ows_LinkFilenameNoMenu="8_.000" ows_LinkFilename="8_.000" ows_ServerUrl="/pdm/Lists/Segments/8_.000" ows_EncodedAbsUrl="http://example.com/pdm/Lists/Segments/8_.000" ows_BaseName="8_" ows_MetaInfo="8;#" ows__Level="1" ows__IsCurrentVersion="1" /></rs:data></listitems></GetListItemsResult></GetListItemsResponse></soap:Body></soap:Envelope>';
    var oParser = new DOMParser();
    var oDOM = oParser.parseFromString(xData, "text/xml");
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Without jQuery
var nodes = oDOM.getElementsByTagNameNS("#RowsetSchema", "row");
for (var i = 0; i < nodes.length; ++i) {
}
pending…
getElementsByTagNameNS()
jQuery(oDOM.getElementsByTagNameNS("#RowsetSchema", "row")).each(function() {});
pending…
z\\:row, row
jQuery(xData).find("z\\:row, row").each(function() {});
pending…
Custom plugin
jQuery(xData.responseXML).find('*').filterNode('z:row').each(function() {

});
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment