querySelectorAll vs getElementById (v76)

Revision 76 of this benchmark created by Andrey Kindin on


Preparation HTML

<p id="foo">bar</p>
<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js"></script>
<script
			  src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
			  integrity="sha256-3edrmyuQ0w65f8gfBsqowzjJe2iM6n0nKciPUp8y+7E="
			  crossorigin="anonymous"></script>

Setup

var select = function(query){
  	if (query[0] == "#"){
  		return document.getElementById(query.slice(1));
  	}else{
  		return document.querySelectorAll(query);
  	}
  };

Test runner

Ready to run.

Testing in
TestOps/sec
select
var result = select("#foo");
ready
getElementById
var result = document.getElementById('foo');
ready
jQuery
var result = jQuery("#foo");
ready
querySelectorAll
var result = document.querySelectorAll('#foo');
ready
Zepto
var result = Zepto("#foo");
ready

Revisions

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