jQuery ID selector performance (v15)

Revision 15 of this benchmark created on


Description

Given an #id selector I was curious to see just how big a difference it would make to save the jQuery object instead of re-instantiating it over and over.

Read the full blog post, jQuery ID selector performance.

Preparation HTML

<script src="//code.jquery.com/jquery-2.1.0.min.js"></script>
<div id="my-id" class="my-class"></div>

Test runner

Ready to run.

Testing in
TestOps/sec
ID selector
var x = $('#my-id');
ready
ID Document Selector
var x = $(document.getElementById('my-id'));
ready

Revisions

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