You probably mean to compare printf (NOT sprintf) with echo because printf and sprintf do two different things, though similar things. printf could be compared to echo because both print a string to the std output or document stream. sprintf works just like printf except for the fact that it returns a string, and does not print anything in the std out by itself.
printf (x);
is equivalent to
echo sprintf (x);
I don't think that the speed matters in comparison between echo and printf. echo Just prints a string. The only expansion done with echo is the variable expansion inside a double-quote string. Example:
echo "$var";
echo is a language construct, and it is not a function like printf. You may use it without parentheses. Maybe (because echo is not an external function like printf) echo is slightly faster than printf.
printf works much like a printf function in C language. It is a way to provide formatted output based on a format string and other arguments passed along with the format string.
printf (x);
is equivalent to
echo sprintf (x);
I don't think that the speed matters in comparison between echo and printf. echo Just prints a string. The only expansion done with echo is the variable expansion inside a double-quote string. Example:
echo "$var";
echo is a language construct, and it is not a function like printf. You may use it without parentheses. Maybe (because echo is not an external function like printf) echo is slightly faster than printf.
printf works much like a printf function in C language. It is a way to provide formatted output based on a format string and other arguments passed along with the format string.