Well this is regarding a program for a competition.
I was submitting a program & finding my metrics to be relatively way slower than the top scorers in terms of total execution speed. All others (page faults, memory…) were similar. I found that when I ran through my program without the printf (or write) my total execution speed (as measured in my own pc) seemed to be similar.
The competition evaluates the output by redirecting the output (with a pipe, i suppose) into a file & matching its MD5 with theirs….
My question is, Is there by any means something in C, that doesn’t write to the output stream but still the pipe gets its input. Or perhaps I am even framing the question wrong. But either way, I am in a fix.
I have been beating my head off with optimizing the algorithm. BTW they accept makefile where many have tried to optimize. For me neither of the optimization flags have worked. I don’t know what else can be done about that too…
If you need to make a program that writes its output to a file, you just need to:
int fd = fopen("/file/path", O_WRONLY);(you may need to check the parameters, it’s been a long time since I’ve done C programming) and thenwrite(fd, ...);orfprintf(fd, ...);dup2()to duplicate the file descriptor to the file descriptor number 1 (i.e. standard output).