https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78549
Bug ID: 78549 Summary: Very slow formatted internal file output Product: gcc Version: 6.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libfortran Assignee: unassigned at gcc dot gnu.org Reporter: mecej4 at operamail dot com Target Milestone: --- Created attachment 40163 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40163&action=edit Program to demonstrate bug Formatted internal writes to a string variable are very slow in many recent versions of GFortran, especially the Windows ports. The attached F77 program, and F95 versions of the same, demonstrate the problem. The heart of the problem is the slowness of write (str,'(1P,10E12.3)') x (where x is a real array of dimension 10), compared to the equivalent call to sprintf in C. Unlike in some old Gfortran bug reports, there are no issues related to Windows versus Linux file system and I/O system discrepancies. NO external FILE I/O is involved. Here are some timings, in seconds, on two systems. SYSTEM: Linux, XEON E5-2630, GFortran/GCC 6.1.1/F2C gfortran -Ofast 6.4 F2C and gcc -Ofast 4.8 gcc -Ofast 1.8 SYSTEM: Windows 10-64 laptop, Haswell i5-4200U CPU F2C, gcc 6.2 -O2 -march=haswell 7.8 G77 -O2 -march=pentium 12.7 gfortran 5.2 32-bit Cygwin 49.6 gfortran 6.2 Mingw-64, Eq.com 65.6 gcc 6.2 5.2 Ifort 17.0.1 2.3 Here is the source code of the C program, which I am placing here since I am allowed only one attachment. #include <stdio.h> int main(){ char str[121]; float x[10]={ 7.569, 5.556, -1.640, 9.362, 1.057, -2.385,-9.541, 1.449, -7.885, -1.108}; int i,j; for(i=0; i<1000000; i++){ sprintf(str,"%12.3e%12.3e%12.3e%12.3e%12.3e%12.3e%12.3e%12.3e%12.3e%12.3e", x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9]); if((i+1)%200000 == 0)printf("%8d %s\n",i+1,str); } }