Selector Performance

Benchmark created by John on


Description

Test selector performance using several selectors in a jQuery call

Preparation HTML

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

<div id="item-1" class="item"> <p>Hello</p><p>World</p><p>!</p> </div>
<div id="item-2" class="item"> <p>Hello</p><p>World</p><p>!</p> </div>

Setup

$item = $("#item-2");
    $items = $(".item");

Test runner

Ready to run.

Testing in
TestOps/sec
Direct child
var item = $("#item-1 > p")
ready
Direct child with context
var item = $("> p", "#item-1");
ready
Direct child with saved context
var item = $("> p", $item);
ready
Direct child with saved multi-item context
var item = $("> p", $items);
ready
Find
var item = $item.find("> p")
ready

Revisions

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