From: jz AT bcsupernet DOT com Newsgroups: comp.os.msdos.djgpp Subject: re:printf("%.6f") Date: 26 Jan 1997 20:42:50 GMT Organization: Zip News Lines: 58 Message-ID: <5cgfka$pp0@clark.zippo.com> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp >On 25 Jan 1997 20:51:52 GMT, jz AT bcsupernet DOT com wrote: > >>Can anyone tell me why my printf("%.6f") is running so incredibly slowly? >>I'm running gcc on a 386 with no copro if that's a clue. The same line >>compiled under Borland C is MUCH faster. this is more than a pmode problem >Is this the only line in your program? If so, then the program compiled >under DJGPP will always run slower. This is because DJGPP spends a lot of >time in startup code compared to a single library function like printf(). No, it isn't the only line in my program, but it is the offending code in terms of speed. I realize it is an incomplete statement. The speed problem is converning the %.6f conversion in formatted output. I know this because I tried sprintf, printf and fprintf all with the same results. I also removed the %.6f conversions and the problem disappeared. The surrounding code is not rellevant to the problem. For example main(){ float a,b,c; int l; a=3.24; b = 0.00423; c = 3464.99887; for(l=1;l <1000;l++){ printf("%.6f %.6f %.6f\n", a,b,c); a+=3.55; b*=1.4; c-= .00024; } } Each iteration of the loop is taking about a half a second. the entire program takes just under 6 minutes to run which is just silly. The same program with the %.6f's taken out takes 10 seconds. With the entire printf removed it takes four seconds. So, obviously the %.6f conversion is very very slow. the question I have is why? And do I have to code my own routine to convert from float to text or does anyone know of one I can just go get (I'm lazy) :) thankyou. >Look at sprintf(). It does everything printf() does, except the output is sent >to a character array (string) which is automatically null-terminated. fprintf, sprintf and printf all take similar lengths of time on %.6f