纯粹的功能 [英] pure functions

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

问题描述

我已阅读某些文章,鼓励使用/编写

纯函数(如果可能),因为它们更适合

优化。


我有一个例子来说明如何优化代码。

例如:


__pure int square(int x)

{

返回x * x;

}


int f(int n)

{

返回square(n)+ square(n);

}


函数f ()可以优化调用纯函数square()一次。


有没有其他方法可以帮助优化纯函数?

是纯函数本身与非纯函数相比,产生了大量优化的代码?

I have read certain articles that encourage to use/write
pure functions (if possible) as they are better suited for
optimization.

I got one example that expalins how the code can be optimised.
For eg:

__pure int square(int x)
{
return x * x;
}

int f(int n)
{
return square(n) + square(n);
}

The function f() can be optimised to call pure function square() once.

Is there any other way pure functions help in optimization ?
Is the pure function itself produce much optimized code as compared
to non pure functions ?

推荐答案

ju ********** @ yahoo.co.in 写道:
我已阅读某些鼓励使用/编写纯函数(如果可能)的文章作为t嘿,它更适合优化。

我有一个例子可以说明如何优化代码。
例如:

__pure int square (int x)
{
返回x * x;
}
int f(int n)
{
返回方块(n )+ square(n);
}

函数f()可以优化调用纯函数square()一次。

还有其他方法纯函数有助于优化吗?
与非纯函数相比,纯函数本身是否产生了大量优化的代码?
I have read certain articles that encourage to use/write
pure functions (if possible) as they are better suited for
optimization.

I got one example that expalins how the code can be optimised.
For eg:

__pure int square(int x)
{
return x * x;
}

int f(int n)
{
return square(n) + square(n);
}

The function f() can be optimised to call pure function square() once.

Is there any other way pure functions help in optimization ?
Is the pure function itself produce much optimized code as compared
to non pure functions ?




你知道吗不是__纯粹的标准C中的关键字(或任何其他

机制,用于指定某个函数是纯粹的),不是吗?


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti .net / ~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



You do know there''s no "__pure" keyword in standard C (or any other
mechanism for specifying that a function is "pure"), don''t you?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.




< ju ********** @ yahoo.co.in>写了

<ju**********@yahoo.co.in> wrote
我读过一些鼓励使用/编写纯函数的文章(如果可能的话),因为它们更适合优化。
I have read certain articles that encourage to use/write
pure functions (if possible) as they are better suited for
optimization.



纯函数是一个好主意,但效率方面的考虑并不是我的原因列表。


pure functions are a good idea, but efficiency considerations wouldn''t be
high on my list of reasons why.


Malcolm写道:
Malcolm wrote:

< ju ********** @ yahoo.co.in>写了

<ju**********@yahoo.co.in> wrote
我读过一些鼓励使用/编写纯函数的文章(如果可能的话),因为它们更适合优化。
I have read certain articles that encourage to use/write
pure functions (if possible) as they are better suited for
optimization.


纯函数是一个好主意,但是效率方面的考虑因为我的原因列表并不高。


pure functions are a good idea,
but efficiency considerations wouldn''t be
high on my list of reasons why.




纯函数不是C的一部分。

这个偏离主题的线程已经过时了。


-

pete



Pure functions aren''t part of C.
This off topic thread has gone on way too long.

--
pete


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

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