Compare every vs reduce performance

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Array Every
const test1 = (a, b) => {
  if (!b?.length) return false;

  return a.every((entry) => b.some((c) => c.d.e === entry));
};

const a = [
  '1',
  '2',
  '3',
  '4'
];
const b = [
  {
    d: { e: '1' }
  },
  {
    d: { e: '2' }
  },
  {
    d: { e: '3' }
  },
  {
    d: { e: '4' }
  }
];

test1(a, b);
ready
Array Reduce
const test1 = (a, b) => {
  if (!b?.length) return false;

  return a.reduce((fetched, entry) => {
    fetched = fetched && b.some((c) => c.d.e === entry);
    return fetched;
  }, true);
};

const a = [
  '1',
  '2',
  '3',
  '4'
];
const b = [
  {
    d: { e: '1' }
  },
  {
    d: { e: '2' }
  },
  {
    d: { e: '3' }
  },
  {
    d: { e: '4' }
  }
];

test1(a, b);
ready

Revisions

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