Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15
Safari 13
Mac OS X 10.15.6
Desktop
4 years ago
Test name Executions per second
getElementById 4272996.5 Ops/sec
querySelector("#id") 2777207.2 Ops/sec
getElementsByClassName("class")[0] 3372902.2 Ops/sec
querySelector(".class") 2916002.5 Ops/sec
getElementById + getElementsByTagName 3752813.8 Ops/sec
querySelectorAll("#id tag") 1688024.6 Ops/sec
getElementById + getElementsByClassName[0] 3149851.8 Ops/sec
querySelector("#id .class") 2713082.5 Ops/sec
getElementsByClassName("class") 3869838.8 Ops/sec
querySelectorAll(".class") 1915822.8 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")


;