Sqrt VS Pow

Hello, I just wanted to ask about the processing times mentioned in video. Gary said that it is way faster to use Pow that Sqrt, however appliance in code showed the opposite. Can you please clarify?

Also tested it on my PC: Pow took around 5 seconds, whereas Sqrt took 1 second to process:

{
    for(int i=0;i<100000000;i++) 
        pow(double(i),0.5);
    

    for(int i=0;i<100000000;i++)
        sqrt(double(i));
    
    return 0; 
}

When equations become more complex, pow is faster than sqrt. This is the case since it is easier to calculate for example the chain rule (when you have some partial derivatives or so).

Kind regards, Lisa

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms