string concatenation

JavaScript performance comparison

Revision 12 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var s, S, A, X, Y, concat = String.prototype.concat;

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
''.concat
'aa'.concat(
  'bb',
  'cc',
  'dd',
  'ee',
  'ff',
  'gg',
  'hh',
  'ii');
pending…
Regular concat, one line
s = '' + 'aa' + 'bb' + 'cc' + 'dd' + 'ee' + 'ff' + 'gg' + 'hh' + 'ii';
pending…
Slash concat
'aa\
bb\
cc\
dd\
ee\
ff\
gg\
hh\
ii';
pending…
regular 2
s = 'aa' +
  'bb' +
  'cc' +
  'dd' +
  'ee' +
  'ff' +
  'gg' +
  'hh' +
  'ii';
pending…
reduce
X = [
  'aa',
  'bb',
  'cc',
  'dd',
  'ee',
  'ff',
  'gg',
  'hh',
  'ii'
].reduce(function(a, b) {
  return a + b;
});
pending…
regular concatenation
s = '';
s += 'aa';
s += 'bb';
s += 'cc';
s += 'dd';
s += 'ee';
s += 'ff';
s += 'gg';
s += 'hh';
s += 'ii';
pending…
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('');
pending…
array join concatenation (all at once)
X = [
  'aa',
  'bb',
  'cc',
  'dd',
  'ee',
  'ff',
  'gg',
  'hh',
  'ii'
].join('');
pending…
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('');
pending…
similar to 3 but using new Array
Y = (new Array(
  'aa',
  'bb',
  'cc',
  'dd',
  'ee',
  'ff',
  'gg',
  'hh',
  'ii'
)).join('');
pending…
String.prototype.concat
concat.call(
  'aa',
  'bb',
  'cc',
  'dd',
  'ee',
  'ff',
  'gg',
  'hh',
  'ii');
pending…

Compare results of other browsers

Revisions

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

0 Comments