Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36
Chrome 85
Mac OS X 10.15.6
Desktop
4 years ago
Test name Executions per second
getElementById 2695774.2 Ops/sec
querySelector("#id") 1581612.5 Ops/sec
getElementsByClassName("class")[0] 2041642.0 Ops/sec
querySelector(".class") 2171591.5 Ops/sec
getElementById + getElementsByTagName 1937806.2 Ops/sec
querySelectorAll("#id tag") 757438.5 Ops/sec
getElementById + getElementsByClassName[0] 1752573.8 Ops/sec
querySelector("#id .class") 2350441.5 Ops/sec
getElementsByClassName("class") 2510279.8 Ops/sec
querySelectorAll(".class") 798654.8 Ops/sec
HTML Preparation code:
Tests:
  • getElementById

  • querySelector("#id")

  • getElementsByClassName("class")[0]

  • querySelector(".class")

  • getElementById + getElementsByTagName

  • querySelectorAll("#id tag")

  • getElementById + getElementsByClassName[0]

  • querySelector("#id .class")

  • getElementsByClassName("class")

  • querySelectorAll(".class")