concat-test (v2)

Revision 2 of this benchmark created on


Setup

const DATA_LENGTH = 1e4;
const ID_LENGTH = 10;

function makeid() {
  let text = "";
  const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  for (let i = 0; i < ID_LENGTH; ++i) {
    text += chars.charAt(Math.floor(Math.random() * chars.length));
  }
  return text;
}

const data = [];

for (let i = 0; i < DATA_LENGTH; ++i) {
  data.push(makeid());
}

Test runner

Ready to run.

Testing in
TestOps/sec
string-templates
let res = '';
for (let i = 0; i < data.length; ++i) {
  res = `${ res }${ data[i] }`;
}
ready
concat
let res = '';
for (let i = 0; i < data.length; ++i) {
  res += data[i];
}
ready
join-with-push
const arr = [];
for (let i = 0; i < data.length; ++i) {
  arr.push(data[i]);
}
const res = arr.join('');
ready
join-without-push
const arr = [];
arr.length = data.length;
for (let i = 0; i < data.length; ++i) {
  arr[i] = data[i];
}
const res = arr.join('');
ready
+
let res = '';
for (let i = 0; i < data.length; ++i) {
  res = res + data[i];
}
ready

Revisions

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