concat vs + vs join

JavaScript performance comparison

Revision 10 of this test case created

Info

How to concat strings faster.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var s1='Coucou ', s2='c\'est ', s3='nous !', t='';
};

Benchmark.prototype.teardown = function() {
    t='';
};
</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
t.concat(s1, s2, s3);
pending…
+
t = s1 + s2 + s3;
pending…
join
t = [s1, s2, s3].join();
pending…
+=
t += s1;
t += s2;
t += s3;
pending…
= t + (x)
t = t + s1;
t = t + s2;
t = t + s3;
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