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 243756.5 Ops/sec
querySelector("#id") 242995.6 Ops/sec
getElementsByClassName("class")[0] 246664.2 Ops/sec
querySelector(".class") 120902.0 Ops/sec
getElementById + getElementsByTagName 63712.1 Ops/sec
querySelectorAll("#id tag") 27512.3 Ops/sec
getElementById + getElementsByClassName[0] 224777.4 Ops/sec
querySelector("#id .class") 119497.3 Ops/sec
getElementsByClassName("class") 64787.0 Ops/sec
querySelectorAll(".class") 25767.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")


;