foreach is slower than for?

2010-09-08 Thread Stanislav Blinov
I was wondering about it for some time: void foreach_loop(int arr[100]) { foreach(i,a; arr) { auto e = a; } } void for_loop(int arr[100]) { for (int i = 0; i < 100; ++i) { auto e = arr[i]; } } compiled with -O -release yields this: .text.void main.forea

Re: foreach is slower than for?

2010-09-08 Thread Tomek Sowiński
Dnia 08-09-2010 o 23:12:55 Stanislav Blinov napisał(a): I was wondering about it for some time: void foreach_loop(int arr[100]) { foreach(i,a; arr) { auto e = a; } } void for_loop(int arr[100]) { for (int i = 0; i < 100; ++i) { auto e = arr[i];

Re: foreach is slower than for?

2010-09-09 Thread Justin Johansson
On 9/09/2010 6:56 AM, Tomek Sowiński wrote: Without -O -release the difference is even greater Is this normal? I mean, shouldn't the compiler optimize foreach a bit more? Or is it that I simply misunderstand generated code? Yes, it should; that was the point of having foreach in the language:

Re: foreach is slower than for?

2010-09-09 Thread Jesse PHillips
Justin Johansson Wrote: > Is there a roadmap for what things are more urgent? The OP has a > valid point in asking what is the point of the language. A decent > roadmap would help newcomers and oldcomers alike to stay with the > Holy Grail of D. > > Justin There is a somewhat official road map

Re: foreach is slower than for?

2010-09-09 Thread Andrej Mitrovic
Are the ones listed under "Known D2" official? There's "Remove C-style declarations." Is this really scheduled for removal? On Thu, Sep 9, 2010 at 8:33 PM, Jesse PHillips wrote: > Justin Johansson Wrote: > >> Is there a roadmap for what things are more urgent?  The OP has a >> valid point in ask

Re: foreach is slower than for?

2010-09-09 Thread Stanislav Blinov
Tomek Sowiński wrote: Dnia 08-09-2010 o 23:12:55 Stanislav Blinov napisał(a): I was wondering about it for some time: void foreach_loop(int arr[100]) { foreach(i,a; arr) { auto e = a; } } void for_loop(int arr[100]) { for (int i = 0; i < 100; ++i) {

Re: foreach is slower than for?

2010-09-09 Thread Stanislav Blinov
Justin Johansson wrote: On 9/09/2010 6:56 AM, Tomek Sowiński wrote: Without -O -release the difference is even greater Is this normal? I mean, shouldn't the compiler optimize foreach a bit more? Or is it that I simply misunderstand generated code? Yes, it should; that was the point of having

Re: foreach is slower than for?

2010-09-09 Thread Jonathan M Davis
On Thursday, September 09, 2010 13:31:13 Stanislav Blinov wrote: > Justin Johansson wrote: > > On 9/09/2010 6:56 AM, Tomek Sowiński wrote: > >>> Without -O -release the difference is even greater > >>> > >>> Is this normal? I mean, shouldn't the compiler optimize foreach a bit > >>> more? Or is it