join/concat (v30)

Revision 30 of this benchmark created on


Description

A simpler check for testing for concat vs join outside of a loop (not building a string in a loop, typical use case would be to use a var in the string).

Preparation HTML

<script>
  var str = 'string';
  var barr = ['this', ' is', ' a', str, ' to', ' test', ' if', ' there', ' is', ' any', ' difference', ' between', ' concat', ' and', ' join'];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
concat
var a = 'this' + ' is' + ' a' + str + ' to' + ' test' + ' if' + ' there' + ' is' + ' any' + ' difference' + ' between' + ' concat' + ' and' + ' join';
ready
join
var a = barr.join('');
ready
concat in a loop
var str = '';
for (var i = 0, ii = barr.length; i < ii; i++) {
  str += barr[i];
}
ready
join on inline array
['this', ' is', ' a', str, ' to', ' test', ' if', ' there', ' is', ' any', ' difference', ' between', ' concat', ' and', ' join'].join('');
ready
join on a Array object
(new Array('this', ' is', ' a', str, ' to', ' test', ' if', ' there', ' is', ' any', ' difference', ' between', ' concat', ' and', ' join')).join("");
ready
Join in a Loop
var strArr = [];
for (var i = 0; i < barr.length; i++) {
  strArr.push(barr[i]);
}
var result = strArr.join();
ready
concat in a "for in" loop
var str = '';
for (i in barr) {
  str += i;
}
ready
forEach
var str = '';
barr.forEach(function(i) {
  str += i;
});
ready

Revisions

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