Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Chrome 112
Windows
Desktop
one year ago
Test name Executions per second
querySelector 1861137.6 Ops/sec
getElementsByName 3561134.0 Ops/sec
getElementById 4930504.0 Ops/sec
getElementsByClassName 3987864.2 Ops/sec
HTML Preparation code:
AخA
 
1
<div name='test' id='test' class='test'></div>
Tests:
  • querySelector

     
    document.querySelector('#test')
  • getElementsByName

     
    document.getElementsByName('div[name="#test"]')
  • getElementById

     
    document.getElementById('test')
  • getElementsByClassName

     
    document.getElementsByClassName(".test")