In awk there are two output functions: print and printf.
- Are their implementations in
awkvery different? - What are the differences regarding performance/speed (if possible — theoretical, not only with “
time” on command line)? - Do they use the same system calls?
printfunction outputs a newline at the end;printfdoes not unless requested.printcode converts the arguments to strings and then sends them to the output separated by the OFS (output field separator).printfcode might need to convert the string to a double before formatting it using a double format (%16.8gor something), and similar operations.write(2)or something similar for both, but there’ll be code (probably<stdio.h>) layered above that.All that adds up to:
printis a little simpler (and therefore faster) thanprintf.printif it will do what you need; useprintfwhen it does what you need.And using a
sprintffollowed byprintis likely to be slower than usingprintfdirectly, so don’t.In case of doubt, measure.