Run details:
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
Chrome 55
Windows
Other
7 years ago
Test name Executions per second
getElementById 310889.9 Ops/sec
querySelector("#id") 286616.6 Ops/sec
getElementsByClassName("class")[0] 303089.3 Ops/sec
querySelector(".class") 193303.4 Ops/sec
getElementById + getElementsByTagName 2285977.8 Ops/sec
querySelectorAll("#id tag") 1320521.9 Ops/sec
getElementById + getElementsByClassName[0] 282449.8 Ops/sec
querySelector("#id .class") 288958.8 Ops/sec
getElementsByClassName("class") 2252973.0 Ops/sec
querySelectorAll(".class") 114419.9 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")


;