This question pertains to ANSI C. I think that it should be a simple answer…so which of these methods is the fastest? It doesn’t really have anything to do with my current projects but it just came to mind one day and I didn’t see the answer right away on the web…
Share
printfis by far preferable, by many orders of magnitude and in every sense. It is a library function that’s part of the C standard, and it makes your own program print the desired output.systemon the other hand launches a new, separate process (something that takes a comparable eternity), and you still have to hope that your shell actually provides anechocommand that does the same thing.The only thing worse than calling
systemonechowould be to callsystemto invoke a compiler that compiles another program that containsprintfand run that, I guess…Don’t use
system.