Run details:
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0
Firefox 55
Windows
Other
7 years ago
Test name Executions per second
getElementById 239449.8 Ops/sec
querySelector("#id") 233847.6 Ops/sec
getElementsByClassName("class")[0] 232259.4 Ops/sec
querySelector(".class") 123337.0 Ops/sec
getElementById + getElementsByTagName 2069198.4 Ops/sec
querySelectorAll("#id tag") 57407.4 Ops/sec
getElementById + getElementsByClassName[0] 0.0 Ops/sec
querySelector("#id .class") 0.0 Ops/sec
getElementsByClassName("class") 2327024.8 Ops/sec
querySelectorAll(".class") 48054.1 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")


;