让它更快 [英] make it faster

查看:60
本文介绍了让它更快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有没有办法让这个功能更快?


struct Points {

双X;

双Y;

};

双倍Dist(积分优先,积分最后)

{

返回pow((First.X-Last.X)*(First.X-Last.X)+(First.Y -

Last.Y) *(First.Y - Last.Y),0.5);

}

Hi,

is there a way to make this function faster???

struct Points {
double X;
double Y;
};
double Dist(Points First, Points Last)
{
return pow( (First.X-Last.X)*(First.X-Last.X) + (First.Y -
Last.Y)*(First.Y - Last.Y) ,0.5);
}

推荐答案

On 2008-02-14 13:10:53 -0500,Simply_Red< Si ********** @ gmail.comsaid:
On 2008-02-14 13:10:53 -0500, Simply_Red <Si**********@gmail.comsaid:




有没有办法让这个功能更快???


struct Points {

double X;

双Y;

};


双倍Dist(积分优先,积分最后)

{

返回pow((First.X-Last.X)*(First.X-Last.X)+(First.Y -

Last.Y)*(First.Y - Last.Y),0.5);

}
Hi,

is there a way to make this function faster???

struct Points {
double X;
double Y;
};
double Dist(Points First, Points Last)
{
return pow( (First.X-Last.X)*(First.X-Last.X) + (First.Y -
Last.Y)*(First.Y - Last.Y) ,0.5);
}



google up''fastsqrt''看看是否有帮助。


-


// kira

google up ''fastsqrt'' and see if it helps.

--

// kira


2008-02-14 19:10,Simply_Red写道:
On 2008-02-14 19:10, Simply_Red wrote:




有没有办法让这个功能更快?


struct Points {

双倍X;

双倍Y;

};


双倍Dist(积分优先,最后一点)

{

返回pow((First.X-Last.X)*(First.X-Last.X)+(First.Y -

Last.Y)*(First.Y - Last.Y),0.5);

}
Hi,

is there a way to make this function faster???

struct Points {
double X;
double Y;
};
double Dist(Points First, Points Last)
{
return pow( (First.X-Last.X)*(First.X-Last.X) + (First.Y -
Last.Y)*(First.Y - Last.Y) ,0.5);
}



你可以尝试使用pow()而不是乘法使用sqrt()

而不是pow(x,0.5)。


但更重要的是,你确定Dist()是你需要的功能

来加快速度吗?


-

Erik Wikstr ?? m

You could try to use the pow() instead of multiplying and using sqrt()
instead of pow(x, 0.5).

But more importantly, are you sure that Dist() is the function you need
to make faster?

--
Erik Wikstr??m


14fév,13:22,Erik Wikstr?m< Erik-wikst ... @ telia.comwrote:
On 14 fév, 13:22, Erik Wikstr?m <Erik-wikst...@telia.comwrote:

2008-02-14 19:10,Simply_Red写道:
On 2008-02-14 19:10, Simply_Red wrote:


Hi,


有没有办法让这个功能更快?
is there a way to make this function faster???


struct Points {

double X;

double Y;

};
struct Points {
double X;
double Y;
};


double Dist(积分优先,积分最后)

{

返回pow(( First.X-Last.X)*(First.X-Last.X)+(First.Y -

Last.Y)*(First.Y - Last.Y),0.5);

}
double Dist(Points First, Points Last)
{
return pow( (First.X-Last.X)*(First.X-Last.X) + (First.Y -
Last.Y)*(First.Y - Last.Y) ,0.5);
}



您可以尝试使用pow()而不是乘法使用sqrt()

而不是pow(x,0.5)。


但更重要的是,你确定Dist()是你需要的功能

来加快速度吗? br />

-

Erik Wikstr?m


You could try to use the pow() instead of multiplying and using sqrt()
instead of pow(x, 0.5).

But more importantly, are you sure that Dist() is the function you need
to make faster?

--
Erik Wikstr?m



我做了一个测试,乘法比pow,

和奇怪的是,pow(x,0.5)比sqrt(x)快。

我必须让我的程序工作得更快,所以我尝试找到它的位置

可能。


I did a test and multiplying is faster than pow,
and what is strange, pow(x,0.5) is faster than sqrt(x).
I have to make my program working faster, so i try to find where it is
possible.


这篇关于让它更快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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