hello.
In general (or from your experience), is there difference in performance between for and while loops?
What if they are doubly/triply nested?
Is vectorization (SSE) affected by loop variant in g++ or Intel compilers?
Thank you
hello.
In general (or from your experience), is there difference in performance between for and while loops?
What if they are doubly/triply nested?
Is vectorization (SSE) affected by loop variant in g++ or Intel compilers?
Thank you
Any intelligent compiler won't really show a difference between them. A for
loop is really just syntactic sugar for a certain form of while
loop, anyways.
it should be negligible. an optimizing compiler should make the distinction nonexistent.
This is something easily ascertained by looking at disassembly. For most loops, they will be the same assuming you do the same work.
int i = 0;
while (i < 10)
++i;
is the same as
for (int i = 0; i < 10; ++i)
;
As for nesting, it really depends on how you configure it but same setups should yield same code.
Should be zero difference, but do check as I've seen really crappy, older versions of GCC create different code ARM/Thumb code between the two. One optimized away a compare after a subtract to set the zero flag where as the other did not. Was very lame.
Nesting again should make no difference. Not sure on SSE/Vectorization stuff, but again I'd expect there to be no difference.