concat vs + vs join (v54)

Revision 54 of this benchmark created on


Description

How to concat strings faster.

Setup

var data = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    
    var position;
    
    position = Math.floor((Math.random() * 21) + 1);
    var a = data.slice(position, position + 5);
    position = Math.floor((Math.random() * 21) + 1);
    var b = data.slice(position, position + 5);
    position = Math.floor((Math.random() * 21) + 1);
    var c = data.slice(position, position + 5);
    
    var temp;

Test runner

Ready to run.

Testing in
TestOps/sec
concat
a.concat(b, c);
ready
+
a + b + c;
ready
join
[a, b, c].join();
ready
+=
temp = '';

temp += a;
temp += b;
temp += c;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.