Random strings joined with += and .join()

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;
}

var randomStrings = Array.from({ length: 100 }, () => randomString(8));

Test runner

Ready to run.

Testing in
TestOps/sec
Concat
let plusEqualResult = "";
for (const str of randomStrings) {
  plusEqualResult += str;
}
ready
Join
const joinResult = randomStrings.join("");
console.log("Joined with .join():", joinResult);
ready

Revisions

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