queue效率问题

 

同样的操作

时间差整整30倍

要是把queue开在循环里面可以上升到90倍!

#include 
#include 
#include 
#include 
#pragma GCC optimize(2)
using namespace std;
queueque;

int main()
{
    int time1, time2, time3;

    time1 = clock();
    for(int i = 1;i <= 1e6;i++)
    {
        int sum = 0;
        for(int ii = 1;ii <= 20;ii++) sum += ii;
    }
    time2 = clock();
    for(int i = 1;i <= 1e6;i++)
    {
        int sum = 0;

        for(int ii = 1;ii <= 20;ii++) que.push(ii);
        while(que.size()) sum += que.front(), que.pop();
    }
    time3 = clock();

    cout << "time1 " << time2 - time1 << endl;
    cout << "time2 " << time3 - time2 << endl;
    return 0;
}

 

你可能感兴趣的:(时间对比,queu,STL,ACM)