jQuery ID selector performance (v4)

Revision 4 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="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="my-id" class="my-class"></div>

Setup

$elem = $('#my-id');

Test runner

Ready to run.

Testing in
TestOps/sec
ID selector
var x = $('#my-id');
ready
ID and tag selector
var x = $('div#my-id');
ready

Revisions

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