Help with clarification

https://ide.codingblocks.com/s/410444

both the functions have the same purpose that is to calculate the diameter. I am not able to understand why the first one is slower and second one is faster.

Hello @raghav007
in the optimised way in which we are using the class we are maintaining the height simultaneously whereas in the other case everytime we have to call for the height function which is more time consuming.
thats why we have are considering the class approach as the optimised appraoch.
if you still have any doubt you can ask here:
Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.