Author: Dieter Buerssner
Date: 16:27:21 01/01/03
Go up one level in this thread
On January 01, 2003 at 19:12:16, Bruce Moreland wrote:
>>>which is faster :
>>>do {} while() or while () {}
>>
>>compilers are very good in handling this but
>>in general
>>
>>do {
>> ..
>>} while();
>>
>>is better for processors (assuming no -O2 but -O) because it
>>will allow fall through prediction of processors better.
>I assume that the compiler is going to get it right. If I need to check up on
>the compiler later, I do. But the point of a high level language is that you
>can write for clarity, and this should be what you do by default.
I don't agree in this specific case. With do {} while you give the compiler more
hints (and also the reader of the source code). You know in advance, that the
loop is executed at least once. It is obvious, that the first test in the
alternative while(test) will be omitted. Sure, most often, it will not make a
significant difference. But it really is different code. And, I have seen cases
in my chess engine, where it seems to make things (very little bit) faster.
Examples might be looping over a piece list. There will (in mamy engines at
least) allways be a K on the board. Something like while (piece_list[i]) or
for (i=0; piece_list[i]; i++) does not take account of this knowledge, and a
compiler most probably can never figure out this.
Regards,
Dieter
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.