Simple String vs Regex

JavaScript performance comparison

Test case created by Joshua Piccari

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var href = 'javascript:openPopUp("http://google.com/")';
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Regex
return href.match(/openPopUp\((['"])?(.*?)\1\)/)[2];
pending…
Simple String
var search = 'openPopUp(';
newHref = href.substring(href.indexOf(search) + search.length + 1);
return newHref.substring(0, href.indexOf(')') - 1);
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