Alex Rivera | Logout

Math.Pow vs multiply operator (performance)

Asked 2009-06-01T20:14:25.200
55

Anyone knows if multiply operator is faster than using the Math.Pow method? Like:

n * n * n

vs

Math.Pow ( n, 3 )
Edit
Report

1 Answer

38

Basically, you should benchmark to see.

Educated Guesswork (unreliable):

In case it's not optimized to the same thing by some compiler...

It's very likely that x * x * x is faster than Math.Pow(x, 3) as Math.Pow has to deal with the problem in its general case, dealing with fractional powers and other issues, while x * x * x would just take a couple multiply instructions, so it's very likely to be faster.

answered 2009-06-01T20:16:41.623

Your Answer