Random String concat

Benchmark created on


Setup

const arr = Array.from({ length: 8192}, () => Math.floor(Math.random() * 10));
let charRand = [
Math.random().toString(),
Math.random().toString(),
Math.random().toString(),
Math.random().toString(),
Math.random().toString(),
Math.random().toString(),
Math.random().toString(),
Math.random().toString(),
Math.random().toString()];

Test runner

Ready to run.

Testing in
TestOps/sec
Append
let len = 8192
for (var res = '', i = 0; i < len; i++) {
 res += charRand[arr[i]];
}
ready
join-with-push
let len = 8192
for (var res = [], i = 0; i < len; i++) {
 res.push(charRand[arr[i]]);
}
res = res.join('');
ready
String plus
let len = 8192

for (var res = '', i = 0; i < len; i++) 
{
 res = res + charRand[arr[i]];
}
ready
Template literal
let len = 8192

for (var res = '', i = 0; i < len; i++) 
{
 res = res + `${charRand[arr[i]]}`;
}
ready
Template literal Append
let len = 8192

for (var res = '', i = 0; i < len; i++) 
{
 res += `${charRand[arr[i]]}`;
}
ready

Revisions

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