replace vs append

JavaScript performance comparison

Test case created by josh

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var article = {};
    article.attributes = {
        id : 12353,
        slug : 'the-post-title-of-the-post',
        permalink : 'http://qz.com/12353/the-post-title-of-the-post/'
    };
   
    var theDomain = 'qz.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
append
var navTo = '/' + article.attributes.id + '/' + article.attributes.slug + '/';
pending…
replace
var navto = article.attributes.permalink.replace('http://' + theDomain, '');
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