Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
querySelectorAll vs getElementsByTagName specific use case 2
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:136.0) Gecko/20100101 Firefox/136.0
Browser:
Firefox 136
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
querySelectorAll
156934.5 Ops/sec
getElementsByTagName
46323.8 Ops/sec
HTML Preparation code:
<body> <div> <script nonce data-something="test"></script> <script nonce data-something="test"></script> <script nonce data-something="test"></script> <script nonce></script> <script nonce></script> <script nonce></script> <div> <script nonce data-something="test"></script> <script nonce data-something="test"></script> <script nonce data-something="test"></script> <script nonce></script> <script nonce></script> <script nonce></script> </div> </div> <script nonce data-something="test"></script> <script nonce data-something="test"></script> <script nonce data-something="test"></script> <script nonce></script> <script nonce></script> <script nonce></script> </body>
Tests:
querySelectorAll
var foundScripts = document.querySelectorAll('body>script'); for (s in foundScripts) { if (foundScripts[s].attributes && foundScripts[s].attributes.length == 1 && foundScripts[s].hasAttribute('nonce') && foundScripts[s].text.substring(0, 19) == 'AF_initDataCallback') { console.log(foundScripts[s]); } }
getElementsByTagName
var foundScripts = document.getElementsByTagName('script'); for (s in foundScripts) { if (foundScripts[s].parentElement == document.body && foundScripts[s].hasOwnProperty('attributes') && foundScripts[s].attributes.length == 1 && foundScripts[s].hasAttribute('nonce') && foundScripts[s].text.substring(0, 19) == 'AF_initDataCallback') { console.log(foundScripts[s]); } }