Append string vs join array (v32)

Revision 32 of this benchmark created by Richard Connamacher on


Setup

var i = 0, str = '', arr = [],
    w1 = 'brown', w2 = 'jumped', w3 = 'lazy';

Test runner

Ready to run.

Testing in
TestOps/sec
String append #1
str += 'Quick ' + w1 + ' fox ' + w2 + ' over the ' + w3 + ' dog. ';
ready
String append #2
str += 'Quick ';
str += w1;
str += ' fox ';
str += w2;
str += ' over the ';
str += w3;
str += ' dog. ';
ready
Array join #2
arr[i++] = 'Quick ' + w1 + ' fox ' + w2 + ' over the ' + w3 + ' dog. ';
arr.join('');
ready
Array join #2
arr[i++] = 'Quick ';
arr[i++] = w1;
arr[i++] = ' fox ';
arr[i++] = w2;
arr[i++] = ' over the ';
arr[i++] = w3;
arr[i++] = ' dog. ';
arr.join('');
ready
Array join #3
arr.push('Quick ');
arr.push(w1);
arr.push(' fox ');
arr.push(w2);
arr.push(' over the ');
arr.push(w3);
arr.push(' dog. ');
arr.join('');
ready
Array literal join
['Quick ',w1,' fox ',w2,' over the ',w3,' dog. '].join('')
ready

Revisions

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