Eithed/RSC

JavaScript performance comparison

Revision 4 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div class="content">
<h1>
  HTML Ipsum Presents
</h1>
<p>
  <strong>
    Pellentesque habitant morbi tristique [Button]C[/Button]
  </strong>
</p>
<p>
  <strong>
    Pellentesque habitant morbi tristique [Button]C[/Button]
  </strong>
</p>
<p>
  <strong>
    Pellentesque habitant morbi tristique [Button]C[/Button]
  </strong>
</p>

</div>

Preparation code output

HTML Ipsum Presents

Pellentesque habitant morbi tristique [Button]C[/Button]

Pellentesque habitant morbi tristique [Button]C[/Button]

Pellentesque habitant morbi tristique [Button]C[/Button]

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Search
$(document).ready(function() {

  $(".content").find(":contains([Button])").each(function() {
    if (!$(this).is("script")) $(this).contents().each(function() {
      if ($(this).get(0).nodeType == 3 && $(this).get(0).nodeValue.indexOf("[Button]") != -1 && $(this).get(0).nodeValue.indexOf("[/Button]") != -1) {
        var _new = $(this).get(0).nodeValue.replace(/\[Button\](.*?)\[\/Button\]/gi, function(stmt, value) {
          return "<a class='button'>" + value + "</a>";
        });
        $(this).before(_new).remove();
      }
    });
  });
});
pending…
Replace
$(document).ready(function() {
  var buttonReplaced = $(".content").html().replace(/\[Button\]/ig, '<a class="button">').replace(/\[\/Button\]/ig, '</a>');
  $(".content").html(buttonReplaced);
});
pending…
$(document).ready(function() {
 var buttonReplaced= $('.content').html().replace(/\[Button\](.*?)\[\/Button\]/gi, '<a class="button">$1</a>');
  $('.content').html(buttonReplaced);
});
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment