getElementById vs querySelector with attribute search

Benchmark created by tzo on


Description

getElementById vs querySelector search attribute

Preparation HTML

<div id="tzo" test="true"><div>

<script>
  var gebi = function(id) {
   if (!id) return null
   var n = document.getElementById(id)
  
   return (n && n.getAttribute("test")) ? n : null
  }
  
  var qs = function(id) {
   if (!id) return null
  
   return document.querySelector("#" + id + "[test]")
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
getElementById
gebi("tzo")
ready
querySelector
qs("tzo")
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.