Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: What a difference...

Author: Rafael Andrist

Date: 09:09:51 01/23/02

Go up one level in this thread


On January 22, 2002 at 21:07:57, Russell Reagan wrote:

>I'm just analyzing a few loops and originally I was using C++ and iostream's
>cout for displaying the result. I wondered if compiling the same thing in C and
>using printf would make any difference...it did. Before I could hardly read the
>ASM because it was strung out with all kinds of garbage. The ASM/source file
>generated using C was 2K, the C++ one was 440K. Go figure, all for this:
>
>#include <stdio.h>
>
>void main() {
>
>	char squares[64];
>	int i;
>	int found = 0;
>
>	for(i = 0; i < 64; i++) {
>
>		if(squares[i] == 1)
>			found = 1;
>
>	}
>
>	printf("%d",found);
>
>}
>
>You think there might be a little hidden overhead in C++?!
>
>Russell

Maybe the compiler decided to change the loop which takes always 64 cycles into
a loopless version.

BTW you can optimize your loop by adding a "break" after setting "found" to 1.

regards
Rafael B. Andrist



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.