79319552

Date: 2024-12-31 08:56:09
Score: 1.5
Natty:
Report link

in classes, you have a few extra features that allow you to have more performance than the object method:

  1. inheritance: Each instance of Dog shares the same constructor and bark() method. It only references that to a certain place in the memory. BUT in the object method, you declare the method and variables within the loop all over again, reducing performance.
  2. caching: methods and everything you construct in classes is cached, no matter how many times you initialize the class (new Dog();) it will only declare for once and will be referred to the cached value or method, unless your class uses a dynamic value for the constructor. but in objects, you are redeclaring the methods 1000000 times. but it's declared once in class

these are the main concepts that classes are faster in this scenario

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (0.5):
Posted by: jexroid