Random strings joined with += and .join() (v11)

Revision 11 of this benchmark created on


Setup

function randomString(length) {
  const chars =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  let result = "";
  for (let i = 0; i < length; i++) {
    result += chars.charAt(Math.floor(Math.random() * chars.length));
  }
  return `${result.substring(0)}`;
}

var randomStrings = Array.from({ length: 50 }, () => randomString(10+Math.floor(Math.random()*500)));

Test runner

Ready to run.

Testing in
TestOps/sec
Concat
let plusEqualResult = "";
for (const str of randomStrings) {
  plusEqualResult += str;
}
console.log("Joined with concat:", !!plusEqualResult.match(/QJK/));
ready
Join
const nocheat=[];
for (const str of randomStrings) {
  nocheat.push(str);
}
const joinResult = nocheat.join("");
console.log("Joined with .join():", !!joinResult.match(/QJK/));
ready
reduce
const reduceResult = randomStrings.reduce((acc, str) => acc + str, "");
console.log("reduced:", !!reduceResult.match(/QJK/));
ready

Revisions

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