Silvi Caching Selectors

Benchmark created by Scott Silvi on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<ul class="breadcrumb">
  <li class="active">
    <span class="divider">
      >
    </span>
  </li>
  <li class="active">
    <span class="divider">
      >
    </span>
  </li>
  <li class="active">
    <span class="divider">
      >
    </span>
  </li>
  <li class="active">
  </li>
</ul>

Setup

var first = "Step View",
        second = "Live",
        third = "Default",
        fourth = "LP";

Test runner

Ready to run.

Testing in
TestOps/sec
No breadcrumb caching
$(".breadcrumb li:first").html(first + '<span class="divider">></span>');
$(".breadcrumb li:nth-child(2)").html(second);
if (third) {
  $(".breadcrumb li:nth-child(3) a").html(second);
  if (fourth) {
    $(".breadcrumb li:nth-child(4) a").html(second);
  } else {
    $(".breadcrumb").remove("li:gt(2)");
  }
} else {
  $(".breadcrumb").remove("li:gt(1)");
}
ready
Breadcrumb caching
var breadcrumb = $(".breadcrumb li");
breadcrumb.find(":first").html(first + '<span class="divider">></span>');
breadcrumb.find(":nth-child(2)").html(second);
if (third) {
  breadcrumb.find(":nth-child(3) a").html(second);
  if (fourth) {
    breadcrumb.find(":nth-child(4) a").html(second);
  } else {
    breadcrumb.remove(":gt(2)");
  }
} else {
  breadcrumb.remove(":gt(1)");
}
ready

Revisions

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

  • Revision 1: published by Scott Silvi on