Vanilla JS, Cash and jQuery - GetID Speed Test

3 years ago
User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
Test name Executions per second
getElementById 2118140.0 Ops/sec
jQuery (tag.id) 142600.0 Ops/sec
jQuery (tag#id) 140775.5 Ops/sec
jQuery (.id) 202669.1 Ops/sec
jQuery (#id) 573389.6 Ops/sec
Cash + getElementsByClassName 286576.4 Ops/sec
Cash + getElementById 367329.8 Ops/sec
Cash (tag.id) 197629.1 Ops/sec
jQuery + getElementById 445647.5 Ops/sec
Cash (tag#id) 182419.7 Ops/sec
Cash (#id) 631870.7 Ops/sec
querySelectorAll (.id) 506762.0 Ops/sec
querySelectorAll (#id) 367671.9 Ops/sec
querySelector (.id) 1050002.0 Ops/sec
querySelector (#id) 1256481.0 Ops/sec
getElementsByTagName 1799583.0 Ops/sec
getElementsByClassName 1406357.0 Ops/sec
Cash (.id) 233648.9 Ops/sec
jQuery + getElementsByClassName 198936.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

Open this result on MeasureThat.net