filter(Boolean).join(' ') vs iteration

Benchmark created on


Setup

const mergeWithFilterJoin = (...ariaLists) => {
  return ariaLists.filter(Boolean).join(' ') || undefined;
};

function mergeWithForEach(...ariaLists) {
  let output = '';
  let prevValue;
  ariaLists.forEach(arg => {
    if (arg) {
      if (prevValue) output += ' ';
      output += arg;
      prevValue = arg;
    }
  });
  return output || undefined;
}

Test runner

Ready to run.

Testing in
TestOps/sec
mergeWithFilterJoin
mergeWithFilterJoin('hello', 'world')
ready
mergeWithForEach
mergeWithForEach('hello', 'world')
ready

Revisions

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