Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
Chrome 71
Windows
Desktop
5 years ago
Test name Executions per second
getElementById 2502217.0 Ops/sec
querySelector("#id") 1222901.1 Ops/sec
getElementsByClassName("class")[0] 1668650.5 Ops/sec
querySelector(".class") 1691051.1 Ops/sec
getElementById + getElementsByTagName 1916785.2 Ops/sec
querySelectorAll("#id tag") 410070.6 Ops/sec
getElementById + getElementsByClassName[0] 1578810.9 Ops/sec
querySelector("#id .class") 1605944.0 Ops/sec
getElementsByClassName("class") 3414412.8 Ops/sec
querySelectorAll(".class") 790247.0 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")