Run details:
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
Chrome 68
Windows 7
Desktop
6 years ago
Test name Executions per second
getElementById() 3032688.0 Ops/sec
getElementsByClassName() 1987858.1 Ops/sec
getElementsByTagName() 2347105.5 Ops/sec
querySelector(#id) 1791084.6 Ops/sec
querySelector(.id) 2399025.2 Ops/sec
querySelectorAll(#id) 757255.3 Ops/sec
querySelectorAll(.id) 864836.0 Ops/sec
jQuery(#id) 1176703.1 Ops/sec
jQuery(.id) 490640.6 Ops/sec
jQuery(tag#id) 261734.5 Ops/sec
jQuery(tag.id) 276696.3 Ops/sec
jQuery + getElementById 1152127.4 Ops/sec
jQuery + getElementsByClassName 399321.7 Ops/sec
HTML Preparation code:
Tests:
  • getElementById

  • getElementsByClassName

  • getElementsByTagName

  • querySelector (#id)

  • querySelector (.id)

  • querySelectorAll (#id)

  • querySelectorAll (.id)

  • Cash (#id)

  • Cash (.id)

  • Cash (tag#id)

  • Cash (tag.id)

  • Cash + getElementById

  • Cash + getElementsByClassName

  • jQuery (#id)

  • jQuery (.id)

  • jQuery (tag#id)

  • jQuery (tag.id)

  • jQuery + getElementById

  • jQuery + getElementsByClassName