Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
Chrome 68
Mac OS X 10.11.6
Desktop
6 years ago
Test name Executions per second
getElementById 2036894.6 Ops/sec
querySelector("#id") 1082780.0 Ops/sec
getElementsByClassName("class")[0] 1369515.8 Ops/sec
querySelector(".class") 1439665.6 Ops/sec
getElementById + getElementsByTagName 1720787.1 Ops/sec
querySelectorAll("#id tag") 405384.0 Ops/sec
getElementById + getElementsByClassName[0] 1413870.9 Ops/sec
querySelector("#id .class") 1427448.6 Ops/sec
getElementsByClassName("class") 1980388.6 Ops/sec
querySelectorAll(".class") 582365.4 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")


;