Very simple C programm:
#include <stdio.h>
int main(int, char**) {
for (int i = 0; i < 500000; i++){
printf("Test %d\n", i);
}
}
If I compile & run this in WSL2 with GCC, this will take 1.187855 seconds.
If I compile & run this in Windows with MinGW64, this will take 84.222000 seconds!?!
I tried it on the 4 terminal/consoles for Windows:
- Powershell 5
- Powershell 7
- Terminal
- CMD
They do not differ significantly from each other.
I tried other code, that does not print anything but calculates something. This code runs equally fast, therefore we're talking specifically about the printf function.
I wouldn't complain of a factor 3 or 4, but a factor of round about 80?!?
Do I miss something here?
Update
As suggested by cforler: You have to edit the buffer by hand:
#include <stdio.h>
int main(int, char**) {
char buf[65536];
setvbuf(stdout, buf, _IOFBF, 65536);
for (int i = 0; i < 500000; i++){
printf("Test %d\n", i);
}
}
This accelerates this program to 5.569000 seconds. Still 5 times slower than WSL2, but good enough for me.