Run details:
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
Chrome 55
Windows
Other
7 years ago
Test name Executions per second
getElementById 3363649.8 Ops/sec
querySelector("#id") 2694349.5 Ops/sec
getElementsByClassName("class")[0] 2690967.5 Ops/sec
querySelector(".class") 456430.2 Ops/sec
getElementById + getElementsByTagName 2427029.2 Ops/sec
querySelectorAll("#id tag") 994125.9 Ops/sec
getElementById + getElementsByClassName[0] 2090988.9 Ops/sec
querySelector("#id .class") 2278006.5 Ops/sec
getElementsByClassName("class") 3154692.8 Ops/sec
querySelectorAll(".class") 142517.5 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")