加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LargeObject.cpp 1.18 KB
一键复制 编辑 原始数据 按行查看 历史
youch 提交于 2019-11-17 17:05 . init
#include <stdio.h>
#include <iostream>
#include <list>
#include <vector>
#include "Timer.hpp"
class LargeObject {
public:
LargeObject();
virtual ~LargeObject();
private:
int m_data[200000];
};
LargeObject::LargeObject() {};
LargeObject::~LargeObject() {};
int main() {
LargeObject obj;
//create a list and a timer for the list
std::list<LargeObject> myList;
Timer listTimer;
for( int i = 0; i < 500; i++ ) {
listTimer.start();
myList.push_back(obj);
listTimer.stop();
}
//create a vector and a timer for the vector
std::vector<LargeObject> myVector;
Timer vectorTimer;
for( int i = 0; i < 500; i++) {
vectorTimer.start();
myVector.push_back(obj);
vectorTimer.stop();
}
//print all times for the list
std::cout << "The times for the list are:\n";
std::list<double>::iterator it1 = listTimer.begin();
while( it1 != listTimer.end() ) {
std::cout << *it1 << " "; it1++;
}
std::cout << "\n\n";
//print all times for the vector
std::cout << "The times for the vector are:\n";
std::list<double>::iterator it2 = vectorTimer.begin();
while( it2 != vectorTimer.end() ) {
std::cout << *it2 << " "; it2++;
}
std::cout << "\n\n";
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化