vector和list插入性能对比

int main()
{
        clock_t t1 =clock();
        vector<string> vec_Str;
        for (int i =0;i<5000001;i++)
        {
                vec_Str.push_back("29843974923752758427598475984759847598427598475982475894752");
        }
         clock_t t2 = clock();
        cout << "vecotr sleep time is " << t2 - t1 << endl;

        list<string> list_Str;
        for (int i = 0; i < 5000000; i++)
        {
                list_Str.push_back("29843974923752758427598475984759847598427598475982475894752");
        }

        cout << "list sleep time is " << clock() - t2 << endl;
        getchar();
        return 0;
}

在windows下和linux下试了这段程序,结果大跌眼镜

windows下vector慢list差不多三倍  而linux下两者相差不大,优势vector反而快一下

猜你喜欢

转载自www.cnblogs.com/wangshaowei/p/11427467.html