Vanilla JS, Cash and jQuery - GetID Speed Test

5 years ago
User agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/71.0.3578.80 Chrome/71.0.3578.80 Safari/537.36
Test name Executions per second
getElementById() 3378420.0 Ops/sec
getElementsByClassName() 2254151.0 Ops/sec
getElementsByTagName() 2704270.0 Ops/sec
querySelector(#id) 2154068.0 Ops/sec
querySelector(.id) 2747993.0 Ops/sec
querySelectorAll(#id) 731948.0 Ops/sec
querySelectorAll(.id) 879539.4 Ops/sec
jQuery(#id) 1088652.0 Ops/sec
jQuery(.id) 599076.3 Ops/sec
jQuery(tag#id) 350930.6 Ops/sec
jQuery(tag.id) 369140.9 Ops/sec
jQuery + getElementById 1369674.0 Ops/sec
jQuery + getElementsByClassName 531102.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

Open this result on MeasureThat.net