concat vs + vs join

JavaScript performance comparison

Revision 5 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 !';
};
</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
s1.concat(s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3);
pending…
+
s1 + s2 + s3 + s1 + s2 + s3 + s1 + s2 + s3 + s1 + s2 + s3 + s1 + s2 + s3 + s1 + s2 + s3 + s1 + s2 + s3 + s1 + s2 + s3 + s1 + s2 + s3 + s1 + s2 + s3 + s1 + s2 + s3 + s1 + s2 + s3;
pending…
join
[s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3, s1, s2, s3].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:

0 comments

Add a comment