Optimizing Immutable and Purity

Walter Bright newshound1 at digitalmars.com
Mon Dec 22 15:18:09 PST 2008


bearophile wrote:
>> one rule that is fairly consistent is that fewer instructions
>> execute faster.<
> 
> Generally this isn't much true anymore.

It is <g>. Try it.

>> On a real program, how much faster is my code going to get, if I
>> maximize use of pure functions and immutable data? I don't know. I
>> don't have any experience with it on a large program.<
> 
> Maybe some programmer already used to pure functional programming can
> give you some answer.

I doubt it. There isn't any other language with D's mix of imperative 
and functional such that you can do a reasonable comparative study.

> Is GCC able to perform similar optimizations (some of them, not all
> of them) when you use the "pure" attribute to functions? See  int
> square (int) __attribute__ ((pure));  in this page: 
> http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

I didn't know gcc had pure functions. It doesn't have immutable data. If 
it does optimize with it, you can try it and see!



More information about the Digitalmars-d mailing list