Jump to content

Archived

This topic is now archived and is closed to further replies.

JRaz

sqrt(x) VS pow(x,1/2)

Recommended Posts

which one of the above is faster? and is pow(x,1/3) the only way to do cube root?

Share this post


Link to post
Share on other sites
1 ) sqrt()
[code]$t1 = microtime(true);
for($i=1;$i<=1000;$i++){
    $x = sqrt($i);
}
$t2 = microtime(true);
for($i=1;$i<=1000;$i++){
    $y = pow($i, 1/2);
}
$t3 = microtime(true);
echo 'sqrt : ', $t2-$t1, '<br>';
echo 'pow  : ', $t3-$t2, '<br>';[/code]

2 ) AFAIK it is the only way.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.