String concatenation (v77)

Revision 77 of this benchmark created by Oleksandr Kelepko on


Description

Different ways to concatenate strings together

Setup

var results = [];
    var nextLorem=(function(){
      var dict=["ad","adipisicing","aliqua","aliquip","amet","anim","aute","cillum",
                        "commodo","consectetur","consequat","culpa","cupidatat","deserunt","do",
                        "dolor","dolore","duis","ea","eiusmod","elit","enim","esse","est","et",
                        "eu","ex","excepteur","exercitation","fugiat","id","in","incididunt",
                        "ipsum","irure","labore","laboris","laborum","Lorem","magna","minim",
                        "mollit","nisi","non","nostrud","nulla","occaecat","officia","pariatur",
                        "proident","qui","quis","reprehenderit","sint","sit","sunt","tempor",
                        "ullamco","ut","velit","veniam","voluptate"];
      var i = 0;        
      return function nextLorem(){
        return dict[i++%dict.length];
        };
    }());

Test runner

Ready to run.

Testing in
TestOps/sec
+
var str=nextLorem()+" "+nextLorem()+" "+nextLorem()+" "+nextLorem()+" "+nextLorem();
results.push(str.toString());
ready
2 x +=
var str=nextLorem();
for(var i=0;i<4;i++){
        str+=" ";
        str+=nextLorem();
}
results.push(str.toString());
ready
+=
var str=nextLorem();
for(var i=0;i<4;i++){
        str+=" "+nextLorem();
}
results.push(str.toString());
ready
Array#join
var str=[nextLorem(),nextLorem(),nextLorem(),nextLorem(),nextLorem()].join(" ");
results.push(str.toString());
ready

Revisions

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