From: Bonita.Montero@gmail.com   
      
   Am 11.12.2025 um 12:46 schrieb bart:   
   > On 11/12/2025 03:35, Paul wrote:   
   >> On Wed, 12/10/2025 5:37 PM, bart wrote:   
   >   
   >>> A getc loop took 4.3 seconds to read a 192MB file from SSD, on my   
   >>> Windows PC.   
   >>>   
   >>> Under WSL it took 8.4 seconds (8.4/0.5 real/user).   
   >>>   
   >>> However reading it all in one go took 0.14 seconds.   
   >>>   
   >>> I guess not all 'getc' implementations are the same.   
   >>   
   >> #include    
   >> #include    
   >> #include    
   >>   
   >> /* gcc -Wl,--stack,1200000000Â -o getcbench.exe getcbench.c */   
   >>   
   >> int main(int argc, char **argv)   
   >> {Â FILE* source;   
   >>   
   >> Â Â Â int c;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â    
    Â Â Â Â Â Â Â Â Â Â Â Â /* getc holder */   
   >> Â Â Â const int size = 1000*1000*1000;   
   >> Â Â Â char keep[size];   
   >   
   > I didn't see the point of either keeping the array on the stack, or   
   > using a VLA. I made it static. That also allowed me a choice of   
   > compilers with no special options needed.   
   Yes. Under Linux/x64 the default stack size is 8MiB, unter Windows/x64   
   one MiB.   
   That's a stack overflow - or should I call it underflow since it grows   
   downards   
   - for sure.   
   >   
   >> Add some code after the fopen.   
   >>   
   >> Â Â Â if (setvbuf(source, NULL, _IOFBF, 65536) != 0)   
   >> Â Â Â {   
   >> Â Â Â Â Â Â Â Â fprintf(stderr, "setvbuf() failed\n\n" );   
   >> Â Â Â Â Â Â Â Â return -1;   
   >> Â Â Â }   
   >   
   > When I added that, it slowed it down! Maybe it was already using a   
   > bigger buffer.   
   >   
   >> Extra code was added so keep[] was not optimized away.   
   >   
   > My loop didn't store the characters anywhere; it just bumped a count.   
   >   
   > I think it was enough that it was calling an external function,   
   > 'getc'; a commpiler can't optimise that away.   
   >   
   >> Read 1000000000 bytes in 001.075651 seconds   
   >>   
   >> Busy sum = FFFFFFFFE216FE9C   
   >>   
   >> That's getting close to a gigabyte per second.   
   >>   
   >> Summary: The -O2 makes a BIG difference.   
   >> Â Â Â Â Â Â Â Â Â No idea how it is cheating.   
   >   
   > How a look at the generated assembly: is it still making an actual   
   > call to 'getc', or has it been inlined?   
   >   
   > In my case -O2 made little difference, and it was still calling   
   > getc(). -O2 can't effect such a precompiled function, unless getc() is   
   > not really an external function: either a macro, or a wrapper.   
   >   
   > Also, the generated EXE file actually imports getc from msvcrt.dll,   
   > which is a library not known to be performant.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|