href vs contains

JavaScript performance comparison

Test case created by CS

Preparation code

<ul class="level-1">
  <li class="item-i">I</li>
  <li class="item-ii">II
    <ul class="level-2">
      <li class="item-a"><a href="http://www.notme.com">A</a></li>
      <li class="item-b">B
        <ul class="level-3">
          <li class="item-1"><a href="http://www.notme.com">1</a></li>
          <li class="item-2"><a href="http://www.notme.com">2</a></li>
          <li class="item-3"><a href="http://www.notme.com">3</a></li>
        </ul>
      </li>
      <li class="item-c">C</li>
    </ul>
  </li>
  <li class="item-iii"><a href="http://www.notme.com">III</a></li>
</ul>
<ul class="level-1">
  <li class="item-i">I</li>
  <li class="item-ii">II
    <ul class="level-2">
      <li class="item-a"><a href="http://www.notme.com">A</a></li>
      <li class="item-b">B
        <ul class="level-3">
          <li class="item-1"><a href="http://www.notme.com">1</a></li>
          <li class="item-2"><a href="http://www.notme.com">2</a></li>
          <li class="item-3"><a href="http://www.notme.com">3</a></li>
        </ul>
      </li>
      <li class="item-c">C</li>
    </ul>
  </li>
  <li class="item-iii"><a href="http://www.notme.com">III</a></li>
</ul>
<ul class="level-1">
  <li class="item-i">I</li>
  <li class="item-ii">II
    <ul class="level-2">
      <li class="item-a"><a href="http://www.notme.com">A</a></li>
      <li class="item-b">B
        <ul class="level-3">
          <li class="item-1"><a href="http://www.notme.com">1</a></li>
          <li class="item-2"><a href="http://www.notme.com">2</a></li>
          <li class="item-3"><a href="http://www.notme.com">3</a></li>
        </ul>
      </li>
      <li class="item-c">C</li>
    </ul>
  </li>
  <li class="item-iii"><a href="http://www.notme.com">III</a></li>
</ul>
<ul class="level-1" id="OuterStart">
  <li class="item-i">I</li>
  <li class="item-ii">II
    <ul class="level-2">
      <li class="item-a">A
        <ul class="level-3a" id="StartHereA">
          <li class="item-0a"><a href="http://www.notme.com">0</a></li>
          <li class="item-1a"><a href="http://www.notme.com">1</a></li>
          <li class="item-2a"><a href="http://www.find2me.com" class="foo">find2me</a></li>
          <li class="item-3a"><a href="http://www.notme.com">3</a></li>
          <li class="item-4a"><a href="http://www.notme.com">4</a></li>
        </ul>
      </li>
      <li class="item-b">B
        <ul class="level-3b" id="StartHereB">
          <li class="item-0b"><a href="http://www.notme.com">0</a></li>
          <li class="item-1b"><a href="http://www.notme.com">1</a></li>
          <li class="item-2b"><a href="http://www.findme.com" class="foo">2</a></li>
          <li class="item-3b"><a href="http://www.notme.com">3</a></li>
          <li class="item-4b"><a href="http://www.notme.com">4</a></li>
        </ul>
      </li>
      <li class="item-c">C</li>
    </ul>
  </li>
  <li class="item-iii"><a href="http://www.notme.com">III</a></li>
</ul>
<ul class="level-1">
  <li class="item-i">I</li>
  <li class="item-ii">II
    <ul class="level-2">
      <li class="item-a"><a href="http://www.notme.com">A</a></li>
      <li class="item-b">B
        <ul class="level-3">
          <li class="item-1"><a href="http://www.notme.com">1</a></li>
          <li class="item-2"><a href="http://www.notme.com">2</a></li>
          <li class="item-3"><a href="http://www.notme.com">3</a></li>
        </ul>
      </li>
      <li class="item-c">C</li>
    </ul>
  </li>
  <li class="item-iii"><a href="http://www.notme.com">III</a></li>
</ul>
<ul class="level-1">
  <li class="item-i">I</li>
  <li class="item-ii">II
    <ul class="level-2">
      <li class="item-a"><a href="http://www.notme.com">A</a></li>
      <li class="item-b">B
        <ul class="level-3">
          <li class="item-1"><a href="http://www.notme.com">1</a></li>
          <li class="item-2"><a href="http://www.notme.com">2</a></li>
          <li class="item-3"><a href="http://www.notme.com">3</a></li>
        </ul>
      </li>
      <li class="item-c">C</li>
    </ul>
  </li>
  <li class="item-iii"><a href="http://www.notme.com">III</a></li>
</ul>
<ul class="level-1">
  <li class="item-i">I</li>
  <li class="item-ii">II
    <ul class="level-2">
      <li class="item-a"><a href="http://www.notme.com">A</a></li>
      <li class="item-b">B
        <ul class="level-3">
          <li class="item-1"><a href="http://www.notme.com">1</a></li>
          <li class="item-2"><a href="http://www.notme.com">2</a></li>
          <li class="item-3"><a href="http://www.notme.com">3</a></li>
        </ul>
      </li>
      <li class="item-c">C</li>
    </ul>
  </li>
  <li class="item-iii"><a href="http://www.notme.com">III</a></li>
</ul>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<script>
var $OuterStart = jQuery('#OuterStart');
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
href
var $x = $("a[href*='www.find2me.com']");
pending…
contains
var $x = $("a:contains(find2me)");
pending…

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

Compare results of other browsers

0 comments

Add a comment