Jump to content


Photo

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


  • Please log in to reply
1 reply to this topic

#1 JRaz

JRaz
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 12 June 2006 - 07:35 AM

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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 12 June 2006 - 10:10 AM

1 ) sqrt()
$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>';

2 ) AFAIK it is the only way.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users