Caching vs Nested lookup

JavaScript performance comparison

Test case created by borisli

Preparation code

<!--Sample DOM-->
<h1>Sample DOM</h1>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<div id="main">
  <div id="content">
  <div id="myDiv" class="myClass">
  <p>Sample content of non-consequence</p>
<a href="#">Terms</a>
<script src=""></script>
Benchmark.prototype.setup = function() {
    var $root = $("#main")
    var $child = $(".myClass");

Preparation code output

Sample DOM

Sample content of non-consequence

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Child lookup in cached parent
var test = $root.find("myClass");
test.css('color', '#EFEFEF');
Cached Child
$child.css('color', '#EFEFEF');

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

Compare results of other browsers


Comment form temporarily disabled.

Add a comment