Speed comparison of fprintf, fputs and FPUTC

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.