Monday, 15 August 2011

r - Why does **0.5 appear to be more efficient than sqrt() -


I have tried to measure the speed of these two methods to take the square root:

  & Gt; System.time (expr = replicate (10000, 1: 10000 ** (1/2))) ## User system passed ## 0.027 0.001 0.028 & gt; System.time (expr = replicate (10000, sqrt (1: 10000)) ## User system has passed ## 3.722 0.665 4.494  

If sqrt () Function can not compete with ** 0.5 , why do we need such a function?

(System is OS X Usumite, and R Version is 3.1.2) < /p>

You forgot important brackets after correcting it:

  system.time (expr = replicate (10000, (1: 10000) ** (1/2)) #user system passed # 4.76 0.32 5.12 System.time (expr = replicate (10000, sqrt (1: 10 000))) # User system has passed # 2.67 0.57 3.31  

No comments:

Post a Comment