string regex testing

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<a href="http://fiddle.jshell.net"></a>
<a href="http://foo.net"></a>
<a href="/foodnet"></a>
<b><span></span></b><div><div></div><div>
<a href="http://jshell.net"></a>
<area>
<map href="http://google.com" />
</area>
<a href="http://www.jshell.net"></a>
 <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></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
test
$("[href^='http']").each(function() {
 var href = $(this).attr('href');
 var result = ((new RegExp(location.host, "i")).test(href)) ? "Matches" : "Doesn't Match"
});
pending…
match
$("[href^='http']").each(function() {
 var href = $(this).attr('href');
 var result = href.match(location.host) ? "Matches" : "Doesn't Match"
});
pending…
search
$("[href^='http']").each(function() {
 var href = $(this).attr('href');
 var result = href.search(location.host) ? "Matches" : "Doesn't Match"
});
pending…
exec
$("[href^='http']").each(function() {
 var href = $(this).attr('href');
 var result = ((new RegExp(location.host, "i")).exec(href)) ? "Matches" : "Doesn't Match"
});
pending…
indexOf
$("[href^='http']").each(function() {
 var href = $(this).attr('href');
 var result = href.indexOf(location.host) > 0 ? "Matches" : "Doesn't Match"
});
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