Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.32 Safari/537.36
Chrome 69
Mac OS X 10.12.6
Desktop
6 years ago
Test name Executions per second
getElementById 2945829.0 Ops/sec
querySelector("#id") 1583179.2 Ops/sec
getElementsByClassName("class")[0] 2456054.2 Ops/sec
querySelector(".class") 2428265.8 Ops/sec
getElementById + getElementsByTagName 2518830.2 Ops/sec
querySelectorAll("#id tag") 555652.1 Ops/sec
getElementById + getElementsByClassName[0] 2021590.1 Ops/sec
querySelector("#id .class") 1929964.9 Ops/sec
getElementsByClassName("class") 2955659.0 Ops/sec
querySelectorAll(".class") 739693.6 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")