string concatenation (v4)

Revision 4 of this benchmark created on


Description

checks different string concatenation methods

Setup

var s, S, A, X, Y, concat = String.prototype.concat;

Test runner

Ready to run.

Testing in
TestOps/sec
regular concatenation
s = '';
s += 'aa';
s += 'bb';
s += 'cc';
s += 'dd';
s += 'ee';
s += 'ff';
s += 'gg';
s += 'hh';
s += 'ii';
ready
array join concatenation
S = [];
S.push('aa');
S.push('bb');
S.push('cc');
S.push('dd');
S.push('ee');
S.push('ff');
S.push('gg');
S.push('hh');
S.push('ii');
S = S.join('');
ready
array join concatenation (all at once)
X = [
'aa',
'bb',
'cc',
'dd',
'ee',
'ff',
'gg',
'hh',
'ii'
].join('');
ready
array init and set before join
A = new Array(9);
A[0] = 'aa';
A[1] = 'bb';
A[2] = 'cc';
A[3] = 'dd';
A[4] = 'ee';
A[5] = 'ff';
A[6] = 'gg';
A[7] = 'hh';
A[8] = 'ii';
A = A.join('');
ready
similar to 3 but using new Array
Y = (new Array(
'aa',
'bb',
'cc',
'dd',
'ee',
'ff',
'gg',
'hh',
'ii'
)).join('');
ready
String.prototype.concat
concat.call(
'aa',
'bb',
'cc',
'dd',
'ee',
'ff',
'gg',
'hh',
'ii');
ready
''.concat
''.concat(
'aa',
'bb',
'cc',
'dd',
'ee',
'ff',
'gg',
'hh',
'ii');
ready

Revisions

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