Run details:
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36
Chrome 71
Windows 7
Desktop
6 years ago
Test name Executions per second
getElementById() 2665047.8 Ops/sec
getElementsByClassName() 1789362.6 Ops/sec
getElementsByTagName() 2255800.8 Ops/sec
querySelector(#id) 1383180.4 Ops/sec
querySelector(.id) 1958346.6 Ops/sec
querySelectorAll(#id) 530263.0 Ops/sec
querySelectorAll(.id) 554953.8 Ops/sec
jQuery(#id) 968440.2 Ops/sec
jQuery(.id) 451862.8 Ops/sec
jQuery(tag#id) 268326.3 Ops/sec
jQuery(tag.id) 285281.8 Ops/sec
jQuery + getElementById 961688.8 Ops/sec
jQuery + getElementsByClassName 462512.3 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