jQuery Selector Performance

Benchmark created by Zafer Hangül on


Preparation HTML

<div id="id" class="class">
    <div class="node"></div>
</div>

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
Globally in #id
var elem = $("#id .node");
ready
Globally in .class
var elem = $(".class .node");
ready
find() in #id
var elem = $("#id").find(".node");
ready
find() in .class
var elem = $(".class").find(".node");
ready
> in #id
var elem = $("#id > .node");
ready
> in .class
var elem = $(".class > .node");
ready
.children() in #id
var elem = $("#id").children(".node");
ready
.children() in .class
var elem = $(".class").children(".node");
ready
with context in #id
var ctx = $("#id"), elem = $(".node",ctx);
 
ready
with context in .class
var ctx = $(".class"), elem = $(".node",ctx);
 
ready

Revisions

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

  • Revision 1: published by Zafer Hangül on