printf more than 5 times faster than std::cout?

后端 未结 6 886
遇见更好的自我
遇见更好的自我 2020-12-09 10:44
#include 
#include 
#include 
#include 

int main(int argc, char* argv[])
{
    std::clock_t start;
    dou         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 11:21

    About 10 years ago, Scott Meyers tested the efficiency of iostream and scanf/printf. Depends on the compiler and environment, sometimes scanf/printf is 20% faster than iostream, sometimes even 200% faster. But iostream was never faster than scanf/printf. According to other two given examples, scanf/printf is still faster than iostream. However, Meyers said that "On a really useful program, there would be no differences." According to Google''s programming style([http://google-styleguide.googlecode.com/svn/trunk/cppguide.html]), streams should not be used except for logging. A replacement for iostream is to encapsule scanf/printf yourself.

提交回复
热议问题