Math.Pow VS乘法运算符(性能) [英] Math.Pow vs multiply operator (performance)

查看:2470
本文介绍了Math.Pow VS乘法运算符(性能)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道,如果乘法运算符比使用Math.Pow方法快?像:

  N * N *ñ
 

VS

  Math.Pow(N,3)
 

解决方案

基本上,你应该基准即可看到。

受过教育的臆测(不可靠的):

如果它不被一些编译器优化,以同样的事情...

这很可能是 X * X * X Math.Pow(X,3)更快 Math.Pow 要处理在一般的情况下的问题,处理分数的权力等问题,而 X * X * X 将只需要几个乘法指令,那么它很可能会更快。

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

n * n * n

vs

Math.Pow ( n, 3 )

解决方案

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.

这篇关于Math.Pow VS乘法运算符(性能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆