0

I am trying to come up with an optimized solution where I need to loop through 1000's of records in an excel sheet.

I have scenarios like:

if (!lei.renewalDate) {
   lei.renewalDate = new Date(record.renewalDate).getTime();
}

if (lei.isManagedByGIDM === undefined || lei.isManagedByGIDM === null) {
   lei.isManagedByGIDM = this.organiseManagedByData(record.managedByOthers);
}

My question is, does it make any sense in checking the existence of renewalDate or can I directly call lei.renewalDate = new Date(record.renewalDate).getTime();?

I am adding an extra check to if I need to call a such small built-in function. I am doing the same in the second condition check, to determine if I need to call in organiseManagedByData method (which is a small function with no other function call in it).

I am trying to learn time and space complexity. Is there a way I can determine the cost of the above code

Pritam Bohra
  • 3,912
  • 8
  • 41
  • 72
  • 1
    Unless you're performing that operation millions and millions of time, it doesn't matter at all. – Pointy May 06 '20 at 16:31
  • 1
    If you only care about runtime, you should benchmark the various solutions. It almost certainly is a negligible difference (if any) in terms of performance. Note that both do different things (in your current implementation, `renewalDate` will not be a key in your object, or will be left as whatever it was before. If you skip the check, it will be `NaN`, which may or may not be an issue for other code. I will add that this type of micro-optimization does not affect the time or space complexity of your solution. – rfestag May 06 '20 at 16:41

0 Answers0