string_concat

Benchmark created on


Setup

const randomValues= [...Array(1000)].map(() => {
  const randomStr = "abcdefghijklmnopqrstuvwxyz".split('').sort(() => .5-Math.random()).join('');
  return randomStr.slice(0, Math.random()*26 + 2)
})

Test runner

Ready to run.

Testing in
TestOps/sec
reduce
let result = Object.values(randomValues).reduce(
    (previous, current) => `${previous} ${current}`,
    ''
  );
ready
+=
let result = ''
const space = ' '
const values = Object.values(randomValues)
for (let i = 0; i < values.length; i ++){
	result += ' ' + values[i]
}

ready
+= predefined space with separate +=
let result = ''
const space = ' '
const values = Object.values(randomValues)
for (let i = 0; i < values.length; i ++){
    result += space 
	result += values[i]
}
ready
concat
let result = ''
const space = ' '
const values = Object.values(randomValues)
for (let i = 0; i < values.length; i ++){
    result = result.concat(space)
    result = result.concat(values[i])
}
ready

Revisions

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