Optimizing Immutable and Purity
newshound1 at digitalmars.com
Mon Dec 22 15:18:09 PST 2008
>> 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:
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