fprintf
,
fputs
,
FPUTC
the speed of comparisonMany friends write the program, the output function is used to use printf, and the following two functions are rarely used, the main reason is probably because printf general strong, function covers the last two functions. What is the problem in the usual situation, but if there is a higher demand for the output speed, the difference between the three is more obvious. The author has done two test programs to detect the speed difference of three functions respectively. (Because the test program is very simple, here is not listed in the ^_^) test one: The output return character '/n ' 1 million times respectively.
table One output single character 1 million times (units: US)
Test serial Number |
fprintf |
Fputs |
Fputc |
1 |
279649 |
238263 |
207539 |
2 |
279787 |
251943 |
208857 |
3 |
279584 |
238508 |
207622 |
4 |
279472 |
238272 |
207537 |
5 |
279776 |
238607 |
207680 |
Test two: Output a A-Z character of a long 26 string 1 million times
table One output string 1 million times (units: US)
Test serial Number |
fprintf |
Fputs |
1 |
645202 |
428150 |
2 |
645396 |
427962 |
3 |
644726 |
427396 |
4 |
645811 |
424421 |
5 |
639071 |
422962 |
Comparisons are not hard to find, for output characters (strings) that do not need to be substituted for a variable, the speed of using fprintf is much slower. The reason is because fprintf involves the processing of variable parameters, there may be some dynamic linked list, such as processing (various specific implementations may be different), by FPRINTF->FPUTS->FPUTC, call constraints increase in turn, the internal processing is relatively gradually simple. Calling different functions for different needs can improve output performance to some extent, such as log servers. In fact, for printf, puts, putchar there is a similar relationship, but because the output to the standard output speed is limited, but also take into account the human eye recognition speed, so call which one is not too much difference.