Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36
Chrome 68
Mac OS X 10.11.6
Desktop
6 years ago
Test name Executions per second
getElementById 2220149.0 Ops/sec
querySelector("#id") 1181788.1 Ops/sec
getElementsByClassName("class")[0] 1754216.8 Ops/sec
querySelector(".class") 1804501.1 Ops/sec
getElementById + getElementsByTagName 1873195.4 Ops/sec
querySelectorAll("#id tag") 434035.1 Ops/sec
getElementById + getElementsByClassName[0] 1623261.8 Ops/sec
querySelector("#id .class") 1505525.9 Ops/sec
getElementsByClassName("class") 2273226.5 Ops/sec
querySelectorAll(".class") 628731.2 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")


;