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 246566.6 Ops/sec
querySelector("#id") 242191.2 Ops/sec
getElementsByClassName("class")[0] 243142.1 Ops/sec
querySelector(".class") 124680.2 Ops/sec
getElementById + getElementsByTagName 1967410.8 Ops/sec
querySelectorAll("#id tag") 61900.1 Ops/sec
getElementById + getElementsByClassName[0] 236695.9 Ops/sec
querySelector("#id .class") 123770.4 Ops/sec
getElementsByClassName("class") 2259688.2 Ops/sec
querySelectorAll(".class") 54556.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")


;