$('#id') vs $(document.getElementById(id)) (v3)

Revision 3 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="id"></div>

Setup

var id, tag;

Test runner

Ready to run.

Testing in
TestOps/sec
$ + sizzle
id  = $('#id');
tag = $('div');
ready
$ + native
id  = $(document.getElementById('id'));
tag = $(document.getElementsByTagName('div'));
ready
native
id  = document.getElementById('id');
tag = document.getElementsByTagName('div');
ready
native 2
id  = document.querySelector('#id');
tag = document.querySelectorAll('div');
ready
$ + native 2
id  = $(document.querySelector('#id'));
tag = $(document.querySelectorAll('div'));
ready

Revisions

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