yet another join vs concat

JavaScript performance comparison

Test case created by Jesse

Info

testing another join vs concat to see which is faster.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = "a",
        b = "b",
        c = "c",
        d = "d",
        e = "e",
        f = "f";
};
</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
concat inline HTML
var htmlString = "<p>" + a + "</p><p>" + b + "</p><p>" + c + "</p><p>" + d + "</p><p>" + e + "</p><p>" + f + "</p>";

return htmlString
pending…
join inline HTML
var htmlString = ["<p>", a, "</p><p>", b, "</p><p>", c, "</p><p>", d, "</p><p>", e, "</p><p>", f, "</p>"];

return htmlString.join('');
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:

1 comment

Jesse (revision owner) commented :

it looks like straight up concatination is faster in all browsers, I tested each version minus safari. I'm tyring to figure out why joining an array of strings is often recommended as best practice on some websites.

Anyone can weigh in on this?

Add a comment