为什么c ++ 14中的cin和cout更快?

时间:2016-10-24 12:58:43

标签: c++11 c++14

他们是如何使cin和cout在C ++ 14中更快地工作的。 我也想知道endl和\ n的影响是什么,它们影响了执行的时间。 我在codeforces ide上测试了这些代码, 并得到以下结果。 c ++ 14 cout with endl:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i=0;
    for(i=0;i<1000000;i++)
    cout<<i<<endl;
}

这需要1699毫秒,

c ++ 14 cout without endl

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i=0;
    for(i=0;i<1000000;i++)
    cout<<i;
}

这需要109毫秒。

c ++ 14 printf without \ n

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i=0;
    for(i=0;i<1000000;i++)
    printf("%d",i);
}

这需要171ms。

c ++ 14 with \ n

#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int i=0;
        for(i=0;i<1000000;i++)
        printf("%d\n",i);
    }

这需要186ms。

我现在没有粘贴代码。

没有endl的C ++ 11 cout花了327ms。

c ++ 11 cout with endl花了2245ms。

c ++ 11 printf没有\ n花了186ms。

c ++ 11 printf,\ n花了218毫秒。

C ++ 14肯定会更快我想知道他们对cin和cout做了什么,为什么endl会增加执行时间。 谢谢。

0 个答案:

没有答案