querySelector vs. getElementsByTagName

JavaScript performance comparison

Revision 319 of this test case created by Pieter Van Parys

Preparation code

<document id="24ba9ea8-90e8-4e67-ba44-27a95f634b82" name="0e98b875-cd6e-44db-946b-91eda4e42ff699 14012019 123536" path="CBA DOCUMENTS\USMC Frito-Lay Inc\0e98b875-cd6e-44db-946b-91eda4e42ff699 14012019 123536.xml" zoom="94.01555035196229" width="210mm" height="297mm" bleedLeft="2mm" bleedTop="2mm" bleedRight="2mm" bleedBottom="2mm" initialLayout="7409B05A-B75E-E753-2C09-DA2E7FF7CEE4" initialLayoutName="[Default]" savedInEditor="true" textLanguage="" chiliVersion="5.4.0.0" foldSettingID="" foldDocIdentifier="" threeDModelID="" threeDModelDocIdentifier="" maxCliTimeout="45" saveInactiveTextPositions="true" documentTitle="" author="" description="" keywords="" copyrightNotice="" copyrightInfoUrl=""><pages numIncludedPages="1"><item id="D99409FA-97E9-EC7A-111D-DA2E7FE0A4F8" name="1" explicitMarginRight="0mm" explicitMarginLeft="0mm" includeInOutputComputed="true" contentType=""><frameContentConstraints limitFonts="inherit" limitFontSize="inherit" limitTextColors="inherit" limitParagraphStyles="inherit" limitCharacterStyles="inherit" limitBorderColors="inherit" limitFillColors="inherit" allowedBorderColors="" allowedCharacterStyles="" allowedFillColors="" allowedFonts="" allowedParagraphStyles="" allowedTextColors="" minFontSize="0.1" maxFontSize="5000" hasAppliedConstraint="false" fontInputType="numeric" fontPulldownValues="6;8;10;12;16;24;36;72" fontStepSize="1" limitImageFitModes="inherit" allowedImageFitModes="" /></item></pages><paragraphStyles><item id="3408751A-6B9A-EBEB-E48B-DA2E7FEF8134" name="[None]" color="AAE65428-A331-9984-F4DB-DA2E7FEBA306" colorName="[Black]" alignToBaseLine="false" applyToNewFrames="false" applyToNewFramesAndPreserveLink="false" textOverprint="false" epubExportTag="" pdfExportTag=""><format color="0" /><indentSettings_1 bulletCharacter="•" textIndent="-5mm" paragraphStartIndent="10mm" active="false" /><indentSettings_2 bulletCharacter="•" textIndent="-5mm" paragraphStartIndent="10mm" active="false" /><indentSettings_3 bulletCharacter="•" textIndent="-5mm" paragraphStartIndent="10mm" active="false" /><indentSettings_4 bulletCharacter="•" textIndent="-5mm" paragraphStartIndent="10mm" active="false" /><indentSettings_5 bulletCharacter="•" textIndent="-5mm" paragraphStartIndent="10mm" active="false" /></item></paragraphStyles><characterStyles><item id="235DDAD7-8D09-9BD5-D8E1-DA2E7FF71B30" name="[None]" color="AAE65428-A331-9984-F4DB-DA2E7FEBA306" colorName="[Black]" epubExportTag="" textOverprint="false"><format color="0" /><underline weight="1" offset="0mm" color="AAE65428-A331-9984-F4DB-DA2E7FEBA306" colorName="[Black]" active="false" /></item></characterStyles><colors editableInPopup="true"><item id="AAE65428-A331-9984-F4DB-DA2E7FEBA306" name="[Black]" r="0" g="0" b="0" c="0" m="0" y="0" k="100" isDocumentColor="true" type="CMYK" editableInPopup="inherit" L="0" A="0" B2="0" hexValue="#000000" /><item id="1EC6E753-5AF3-74AA-70A0-DA2E7FEA2A32" name="[None]" r="0" g="0" b="0" c="0" m="0" y="0" k="100" isDocumentColor="true" type="CMYK" editableInPopup="inherit" L="0" A="0" B2="0" hexValue="#000000" /><item id="17B18193-E93A-4E35-B1D3-DA2E7FEC1786" name="[White]" r="0" g="0" b="0" c="0" m="0" y="0" k="0" isDocumentColor="true" type="CMYK" editableInPopup="inherit" L="0" A="0" B2="0" hexValue="#fefefe" /></colors><layers><item id="D2046C3E-E97E-D4E1-B1EA-DA2E7FE89128" name="New Layer" moveRegion="" contentType="" textLanguage=""><frameContentConstraints limitFonts="inherit" limitFontSize="inherit" limitTextColors="inherit" limitParagraphStyles="inherit" limitCharacterStyles="inherit" limitBorderColors="inherit" limitFillColors="inherit" allowedBorderColors="" allowedCharacterStyles="" allowedFillColors="" allowedFonts="" allowedParagraphStyles="" allowedTextColors="" minFontSize="0.1" maxFontSize="5000" hasAppliedConstraint="false" fontInputType="numeric" fontPulldownValues="6;8;10;12;16;24;36;72" fontStepSize="1" limitImageFitModes="inherit" allowedImageFitModes="" /></item></layers><variables notes="" defaultTextDirection="ltr" /><fonts><item id="BAD09682-F7E7-06A7-4E60-DA2E7FE9CB8B" name="Arial Regular" family="Arial" style="Regular" swfURL="http://localhost/ChiliWeb/CAAM/download.aspx?apiKey=xyl678LaRqKrOK0VNtB9Hhez4qeTgC9ypdg8e5DLcTSP5oDAE_7YlxymUmhdSerDrBQLMDLyjlclF4VzEIWM9A==&amp;resourceName=Fonts&amp;id=BAD09682-F7E7-06A7-4E60-DA2E7FE9CB8B&amp;path=&amp;name=Arial%20Regular&amp;type=swf&amp;page=&amp;client_app=Editor_CLI&amp;c_v=3" /></fonts><alternateLayouts><item id="7409B05A-B75E-E753-2C09-DA2E7FF7CEE4" name="[Default]" mobileOutputPurpose="" storyMode="never" /></alternateLayouts><preflightPreferences textOverflow="warning" imageOutputResolution="warning" imageResize="ignore" requiredVariable="warning" frameOutsidePage="warning" preventSaveOnErrors="true" minOutputResolution="72" minResizePercentage="70" maxResizePercentage="120" preventPdfGenerationOnErrors="true" showWarningsOnSave="false" imageOutputResolutionType="bitmap" imageResizeType="vector" missingCharacter="warning" /><preflightResults numErrors="0" numWarnings="0" /><adSettings adSettingsID="" showTypeOverlays="true" publicationID="" showNoteIcons="false" showNoteOverlays="false" showNoteOverlaysForBlanks="true" /><viewPreferences measurementUnit="mm" displayQuality="highest" viewMode="edit" pageMode="normal" pageFlowColumns="calculate" marginBetweenSpreads="false" showPageRulers="false" showHelpLayers="false" bgColor="16777215" pageVisibilityMode="show" initialZoom="fitpage" minZoom="20" maxZoom="300" pageMarginsX="25" pageMarginsY="25" bookViewShowTypeOverlays="false" bookViewNavigation="book" bookViewCornerTease="true" bookViewHardCovers="false" bookViewPageSlope="true" bookViewIncludeAnnotations="true" bookViewAllowEditAnnotations="true" bookViewTransitionActive="false" bookViewTransitionInterval="5" bookViewTransitionLoop="true" bookViewTransitionFinalURL="" bookViewPortraitLayout="B39EAF7C-281B-E3B1-C7B7-DA2E7EB8B53D" bookViewPortraitLayoutName="[Default]" bookViewLandScapeLayout="B39EAF7C-281B-E3B1-C7B7-DA2E7EB8B53D" bookViewLandScapeLayoutName="[Default]" showBookPageLabels="false" bookViewShowSpreads="true" bookViewSpreadColFlow="2" bookViewColumnWidth="300" bookMarginsX="20" zoomShortCutIncrement="25" bookMarginsY="20" showHelp="true" showHiddenCharacters="false" sourceView="false" mouseWheelZooms="false" replaceContentOnDrag="true" rotateView="0" wrapMargins="true" showTextColumns="true" showMargins="true" showBorders="true" bordersOnMouseOver="true" showInset="true" showSections="true" showBleed="true" showSlug="false" showGrid="false" gridX="0mm" gridY="0mm" gridSize="10mm" snapToGrid="false" snapToObjects="true" snapSize="8" showMoveRegions="true" showWarnings="true" showChain="true" showTabRuler="true" useDefaultPlaceHolderText="true" customPlaceHolderText="Type here..." repeatCustomPlaceHolderText="true" fillNewTextFrames="false" autoSelectNewTexts="false" autoTextCursor="false" createBulletLists="true" superScriptOrdinals="true" defaultImageFit="proportional" bookViewIncludeLinks="true" showPageLabels="false" snapFrameMinWidth="10" snapFrameMinHeight="10" snapGuideVisibility="500" allowPasteTextShortcuts="true" fontSizeIncrements="1" showDocumentBaseLineGrid="false" showTextFrameBaseLineGrid="false" liveTextUpdates="true" defaultRgbColorEditType="" defaultColorType="CMYK" allowZoomShortCuts="true" bookViewOpenOnFirstPage="true" showFrameHoverHighlight="false" pageCanvasMarginX="90" pageCanvasMarginY="90" pageFitMarginX="18" pageFitMarginY="18" allowCopyPasteShortcuts="true" allowUndoRedoShortcuts="true" showMissingCharacters="true" copyPasteForContent=""><spellCheckPreferences enabled="true" ignoreWordWithAllUpperCase="false" ignoreWordWithNumber="false" /><storyViewPreferences editWithFormatting="true" plainTextSize="14" plainTextColor="0" plainTextBackground="14540253" endUserCanToggle="false" plainHiddenCharacterColor="255" highlightVariables="true" highlightConditions="true" highlightVariableColor="65280" highlightConditionColor="16711680" /><annotationSettings allowEditOldAnnotations="true" allowEditOtherUsersAnnotations="true" /><linkSettings baseURL="" showToolTips="true" showAutomaticToolTip="true" showBackground="true" backgroundColor="255" showHover="true" backgroundHoverColor="65280" backgroundOpacity="25" backgroundColorRGB="255,255,255" /><frameHandlePreferences cornerHandleType="circle" cornerHandleWidth="8" cornerHandleBgColor="10079487" cornerHandleBorderColor="0" cornerHandleBorderWeight="0.5" sideHandleType="rectangle" sideHandleWidth="6" sideHandleBgColor="10079487" sideHandleBorderColor="0" sideHandleBorderWeight="0.5" rotationHandleType="circle" rotationHandleWidth="10" rotationHandleBgColor="10079487" rotationHandleBorderColor="0" rotationHandleBorderWeight="0.5" showMoveHandle="false" allowInlinePositioning="false" showMoveHandleForText="true" rotationHandleLocation="bottom_right" rotationHandleFromCenter="false" transparent="true" nudgeIncrement="1 mm" showSwapContentHandle="false" /></viewPreferences><importWarnings importedFrom="" importDate="" originalPath="" importedBy="" extensionVersion="" /><dataSource dataSourceID="" xmlString="" fileName="" hasContent="false" numRows="0" selectedFile="" selectedQuery="" lastLoadedQueryString="" selectedSpreadsheet="" /><frameContentConstraints limitFonts="inherit" limitFontSize="inherit" limitTextColors="inherit" limitParagraphStyles="inherit" limitCharacterStyles="inherit" limitBorderColors="inherit" limitFillColors="inherit" allowedBorderColors="" allowedCharacterStyles="" allowedFillColors="" allowedFonts="" allowedParagraphStyles="" allowedTextColors="" minFontSize="0.1" maxFontSize="5000" hasAppliedConstraint="false" fontInputType="numeric" fontPulldownValues="6;8;10;12;16;24;36;72" fontStepSize="1" limitImageFitModes="inherit" allowedImageFitModes="" /><baseLineGridOptions relativeStart="page_top" /></document>
      
<script>
Benchmark.prototype.setup = function() {
  root = document.getElementById("24ba9ea8-90e8-4e67-ba44-27a95f634b82");

};
</script>

Preparation code output

<document id="24ba9ea8-90e8-4e67-ba44-27a95f634b82" name="0e98b875-cd6e-44db-946b-91eda4e42ff699 14012019 123536" path="CBA DOCUMENTS\USMC Frito-Lay Inc\0e98b875-cd6e-44db-946b-91eda4e42ff699 14012019 123536.xml" zoom="94.01555035196229" width="210mm" height="297mm" bleedLeft="2mm" bleedTop="2mm" bleedRight="2mm" bleedBottom="2mm" initialLayout="7409B05A-B75E-E753-2C09-DA2E7FF7CEE4" initialLayoutName="[Default]" savedInEditor="true" textLanguage="" chiliVersion="5.4.0.0" foldSettingID="" foldDocIdentifier="" threeDModelID="" threeDModelDocIdentifier="" maxCliTimeout="45" saveInactiveTextPositions="true" documentTitle="" author="" description="" keywords="" copyrightNotice="" copyrightInfoUrl=""><pages numIncludedPages="1"><item id="D99409FA-97E9-EC7A-111D-DA2E7FE0A4F8" name="1" explicitMarginRight="0mm" explicitMarginLeft="0mm" includeInOutputComputed="true" contentType=""><frameContentConstraints limitFonts="inherit" limitFontSize="inherit" limitTextColors="inherit" limitParagraphStyles="inherit" limitCharacterStyles="inherit" limitBorderColors="inherit" limitFillColors="inherit" allowedBorderColors="" allowedCharacterStyles="" allowedFillColors="" allowedFonts="" allowedParagraphStyles="" allowedTextColors="" minFontSize="0.1" maxFontSize="5000" hasAppliedConstraint="false" fontInputType="numeric" fontPulldownValues="6;8;10;12;16;24;36;72" fontStepSize="1" limitImageFitModes="inherit" allowedImageFitModes="" /></item></pages><paragraphStyles><item id="3408751A-6B9A-EBEB-E48B-DA2E7FEF8134" name="[None]" color="AAE65428-A331-9984-F4DB-DA2E7FEBA306" colorName="[Black]" alignToBaseLine="false" applyToNewFrames="false" applyToNewFramesAndPreserveLink="false" textOverprint="false" epubExportTag="" pdfExportTag=""><format color="0" /><indentSettings_1 bulletCharacter="•" textIndent="-5mm" paragraphStartIndent="10mm" active="false" /><indentSettings_2 bulletCharacter="•" textIndent="-5mm" paragraphStartIndent="10mm" active="false" /><indentSettings_3 bulletCharacter="•" textIndent="-5mm" paragraphStartIndent="10mm" active="false" /><indentSettings_4 bulletCharacter="•" textIndent="-5mm" paragraphStartIndent="10mm" active="false" /><indentSettings_5 bulletCharacter="•" textIndent="-5mm" paragraphStartIndent="10mm" active="false" /></item></paragraphStyles><characterStyles><item id="235DDAD7-8D09-9BD5-D8E1-DA2E7FF71B30" name="[None]" color="AAE65428-A331-9984-F4DB-DA2E7FEBA306" colorName="[Black]" epubExportTag="" textOverprint="false"><format color="0" /><underline weight="1" offset="0mm" color="AAE65428-A331-9984-F4DB-DA2E7FEBA306" colorName="[Black]" active="false" /></item></characterStyles><colors editableInPopup="true"><item id="AAE65428-A331-9984-F4DB-DA2E7FEBA306" name="[Black]" r="0" g="0" b="0" c="0" m="0" y="0" k="100" isDocumentColor="true" type="CMYK" editableInPopup="inherit" L="0" A="0" B2="0" hexValue="#000000" /><item id="1EC6E753-5AF3-74AA-70A0-DA2E7FEA2A32" name="[None]" r="0" g="0" b="0" c="0" m="0" y="0" k="100" isDocumentColor="true" type="CMYK" editableInPopup="inherit" L="0" A="0" B2="0" hexValue="#000000" /><item id="17B18193-E93A-4E35-B1D3-DA2E7FEC1786" name="[White]" r="0" g="0" b="0" c="0" m="0" y="0" k="0" isDocumentColor="true" type="CMYK" editableInPopup="inherit" L="0" A="0" B2="0" hexValue="#fefefe" /></colors><layers><item id="D2046C3E-E97E-D4E1-B1EA-DA2E7FE89128" name="New Layer" moveRegion="" contentType="" textLanguage=""><frameContentConstraints limitFonts="inherit" limitFontSize="inherit" limitTextColors="inherit" limitParagraphStyles="inherit" limitCharacterStyles="inherit" limitBorderColors="inherit" limitFillColors="inherit" allowedBorderColors="" allowedCharacterStyles="" allowedFillColors="" allowedFonts="" allowedParagraphStyles="" allowedTextColors="" minFontSize="0.1" maxFontSize="5000" hasAppliedConstraint="false" fontInputType="numeric" fontPulldownValues="6;8;10;12;16;24;36;72" fontStepSize="1" limitImageFitModes="inherit" allowedImageFitModes="" /></item></layers><variables notes="" defaultTextDirection="ltr" /><fonts><item id="BAD09682-F7E7-06A7-4E60-DA2E7FE9CB8B" name="Arial Regular" family="Arial" style="Regular" swfURL="http://localhost/ChiliWeb/CAAM/download.aspx?apiKey=xyl678LaRqKrOK0VNtB9Hhez4qeTgC9ypdg8e5DLcTSP5oDAE_7YlxymUmhdSerDrBQLMDLyjlclF4VzEIWM9A==&amp;resourceName=Fonts&amp;id=BAD09682-F7E7-06A7-4E60-DA2E7FE9CB8B&amp;path=&amp;name=Arial%20Regular&amp;type=swf&amp;page=&amp;client_app=Editor_CLI&amp;c_v=3" /></fonts><alternateLayouts><item id="7409B05A-B75E-E753-2C09-DA2E7FF7CEE4" name="[Default]" mobileOutputPurpose="" storyMode="never" /></alternateLayouts><preflightPreferences textOverflow="warning" imageOutputResolution="warning" imageResize="ignore" requiredVariable="warning" frameOutsidePage="warning" preventSaveOnErrors="true" minOutputResolution="72" minResizePercentage="70" maxResizePercentage="120" preventPdfGenerationOnErrors="true" showWarningsOnSave="false" imageOutputResolutionType="bitmap" imageResizeType="vector" missingCharacter="warning" /><preflightResults numErrors="0" numWarnings="0" /><adSettings adSettingsID="" showTypeOverlays="true" publicationID="" showNoteIcons="false" showNoteOverlays="false" showNoteOverlaysForBlanks="true" /><viewPreferences measurementUnit="mm" displayQuality="highest" viewMode="edit" pageMode="normal" pageFlowColumns="calculate" marginBetweenSpreads="false" showPageRulers="false" showHelpLayers="false" bgColor="16777215" pageVisibilityMode="show" initialZoom="fitpage" minZoom="20" maxZoom="300" pageMarginsX="25" pageMarginsY="25" bookViewShowTypeOverlays="false" bookViewNavigation="book" bookViewCornerTease="true" bookViewHardCovers="false" bookViewPageSlope="true" bookViewIncludeAnnotations="true" bookViewAllowEditAnnotations="true" bookViewTransitionActive="false" bookViewTransitionInterval="5" bookViewTransitionLoop="true" bookViewTransitionFinalURL="" bookViewPortraitLayout="B39EAF7C-281B-E3B1-C7B7-DA2E7EB8B53D" bookViewPortraitLayoutName="[Default]" bookViewLandScapeLayout="B39EAF7C-281B-E3B1-C7B7-DA2E7EB8B53D" bookViewLandScapeLayoutName="[Default]" showBookPageLabels="false" bookViewShowSpreads="true" bookViewSpreadColFlow="2" bookViewColumnWidth="300" bookMarginsX="20" zoomShortCutIncrement="25" bookMarginsY="20" showHelp="true" showHiddenCharacters="false" sourceView="false" mouseWheelZooms="false" replaceContentOnDrag="true" rotateView="0" wrapMargins="true" showTextColumns="true" showMargins="true" showBorders="true" bordersOnMouseOver="true" showInset="true" showSections="true" showBleed="true" showSlug="false" showGrid="false" gridX="0mm" gridY="0mm" gridSize="10mm" snapToGrid="false" snapToObjects="true" snapSize="8" showMoveRegions="true" showWarnings="true" showChain="true" showTabRuler="true" useDefaultPlaceHolderText="true" customPlaceHolderText="Type here..." repeatCustomPlaceHolderText="true" fillNewTextFrames="false" autoSelectNewTexts="false" autoTextCursor="false" createBulletLists="true" superScriptOrdinals="true" defaultImageFit="proportional" bookViewIncludeLinks="true" showPageLabels="false" snapFrameMinWidth="10" snapFrameMinHeight="10" snapGuideVisibility="500" allowPasteTextShortcuts="true" fontSizeIncrements="1" showDocumentBaseLineGrid="false" showTextFrameBaseLineGrid="false" liveTextUpdates="true" defaultRgbColorEditType="" defaultColorType="CMYK" allowZoomShortCuts="true" bookViewOpenOnFirstPage="true" showFrameHoverHighlight="false" pageCanvasMarginX="90" pageCanvasMarginY="90" pageFitMarginX="18" pageFitMarginY="18" allowCopyPasteShortcuts="true" allowUndoRedoShortcuts="true" showMissingCharacters="true" copyPasteForContent=""><spellCheckPreferences enabled="true" ignoreWordWithAllUpperCase="false" ignoreWordWithNumber="false" /><storyViewPreferences editWithFormatting="true" plainTextSize="14" plainTextColor="0" plainTextBackground="14540253" endUserCanToggle="false" plainHiddenCharacterColor="255" highlightVariables="true" highlightConditions="true" highlightVariableColor="65280" highlightConditionColor="16711680" /><annotationSettings allowEditOldAnnotations="true" allowEditOtherUsersAnnotations="true" /><linkSettings baseURL="" showToolTips="true" showAutomaticToolTip="true" showBackground="true" backgroundColor="255" showHover="true" backgroundHoverColor="65280" backgroundOpacity="25" backgroundColorRGB="255,255,255" /><frameHandlePreferences cornerHandleType="circle" cornerHandleWidth="8" cornerHandleBgColor="10079487" cornerHandleBorderColor="0" cornerHandleBorderWeight="0.5" sideHandleType="rectangle" sideHandleWidth="6" sideHandleBgColor="10079487" sideHandleBorderColor="0" sideHandleBorderWeight="0.5" rotationHandleType="circle" rotationHandleWidth="10" rotationHandleBgColor="10079487" rotationHandleBorderColor="0" rotationHandleBorderWeight="0.5" showMoveHandle="false" allowInlinePositioning="false" showMoveHandleForText="true" rotationHandleLocation="bottom_right" rotationHandleFromCenter="false" transparent="true" nudgeIncrement="1 mm" showSwapContentHandle="false" /></viewPreferences><importWarnings importedFrom="" importDate="" originalPath="" importedBy="" extensionVersion="" /><dataSource dataSourceID="" xmlString="" fileName="" hasContent="false" numRows="0" selectedFile="" selectedQuery="" lastLoadedQueryString="" selectedSpreadsheet="" /><frameContentConstraints limitFonts="inherit" limitFontSize="inherit" limitTextColors="inherit" limitParagraphStyles="inherit" limitCharacterStyles="inherit" limitBorderColors="inherit" limitFillColors="inherit" allowedBorderColors="" allowedCharacterStyles="" allowedFillColors="" allowedFonts="" allowedParagraphStyles="" allowedTextColors="" minFontSize="0.1" maxFontSize="5000" hasAppliedConstraint="false" fontInputType="numeric" fontPulldownValues="6;8;10;12;16;24;36;72" fontStepSize="1" limitImageFitModes="inherit" allowedImageFitModes="" /><baseLineGridOptions relativeStart="page_top" /></document>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
getElementsByTagName
var bar = root.getElementsByTagName("p")[0]
pending…
querySelector
var bar = root.querySelector("p");
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.

0 Comments