Obj ref vs Variable (v2)

Revision 2 of this benchmark created on


Setup

const Workflows = {
	REMARKETING: '1',
  PURCHASE_LEASE_BACK: '2'
}
const vehicles = [];
for (let i = 0; i < 1000; i++) {
	vehicles.push({assetid: i, wftype: Math.floor((Math.random() * 2) + 1).toString()})
}

Test runner

Ready to run.

Testing in
TestOps/sec
Test Ref
function testRef (items) {
	const wfIds = items.reduce((d, v) => {
      d[v.assetid] = d[v.assetid] || {};
      if (v.wftype === Workflows.REMARKETING) {
        d[v.assetid].bd = v.id;
      } else if (v.wftype === Workflows.PURCHASE_LEASE_BACK) {
        d[v.assetid].plb = v.id;
      }
      return d;
    }, {});
  return wfIds;
}
testRef(vehicles);
ready
Test Var
function testVar (items) {
	const wfIds = items.reduce((d, v) => {
      let x = d[v.assetid];
      if (!x) {
        x = {};
        d[v.assetid] = x;
      }
      if (v.wftype === Workflows.REMARKETING) {
        x.bd = v.id;
      } else if (v.wftype === Workflows.PURCHASE_LEASE_BACK) {
        x.plb = v.id;
      }
      return d;
    }, {});
  return wfIds;
}
testVar(vehicles)
ready
Test Ref w/ if
function testRefWithIf (items) {
	const wfIds = items.reduce((d, v) => {
      if (!d[v.assetid]) {
        d[v.assetid] = {};	
      }
      if (v.wftype === Workflows.REMARKETING) {
        d[v.assetid].bd = v.id;
      } else if (v.wftype === Workflows.PURCHASE_LEASE_BACK) {
        d[v.assetid].plb = v.id;
      }
      return d;
    }, {});
  return wfIds;
}
testRefWithIf(vehicles);
ready

Revisions

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