From: SerDevian Newsgroups: comp.os.msdos.djgpp Subject: Strange speed behaviour (fflush()) Date: Tue, 18 Feb 1997 13:41:27 -0700 Organization: XYZZ Software Co. Lines: 56 Message-ID: <330A13F6.41C6@CS.ColoState.edu> NNTP-Posting-Host: miro.vis.colostate.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp I've noticed something quite unexpected in a program of mine... Maybe someone here has some sort of explanation. (?) The program is a graphical program that uses the "far" pointer method of accessing the screen. This works fine. The thing that confuses me is that if I add a "fflush(stdout)" before the main graphical loop, the program speeds up by about 10 fps (80 -> 90 fps). I figured at first that maybe having something hanging in the buffer caused something to be lurking in the background, slowing things down; but that explanation doesn't make sense within this particular program because I flush stdout before the main loop anyway. Maybe fflush() modifies the timer? The important parts of the source look like this: void main() { ... Initialize a few tables, load a couple data files ... printf("some sort of status\n"); // if I use this line, the graphic loop goes faster... // fflush(stdout); printf("another status\n"); fflush(stdout); // this fflush(stdout) is not the strange one. set_graphics_mode(); start_fps_counter(); run_graphical_stuff(); end_fps_counter(); set_text_mode(); } The graphical part of the program does absolutely nothing that uses stdout. BTW, I'm compiling with -O3, which is probably the cause of the speed change, but I don't see why gcc would optimize differently with that one extra line added. ================== There is one other strange behavior I noticed with optimization... (same program) It probably isn't important, though (due to cache or pipelining maybe). In the innermost loop, the program slows down by about 10-15 fps if I *take out* two lines in the loop. (they are just "var += constant;" lines) I thought I would be clever by optimizing those two lines out of the inner loop, but it caused slowdown instead. Even if I leave things as they were, but comment out the two lines, the program still slows down... -- Yamaha / XYZZ "May farce the with be you." mailto:scriven AT CS DOT ColoState DOT edu mailto:scriven AT VIS DOT ColoState DOT edu http://www.vis.colostate.edu/~scriven/