Paste_Image.png
DWORD key = 0;
auto nowClock = GetTickCount();
vector<pair<DWORDLONG, FileInfo>> data;
vector<SortItem> itemdata;
FileInfo file_info;
HANDLE handle = GetCurrentProcess();
PROCESS_MEMORY_COUNTERS pmc;
GetProcessMemoryInfo(handle, &pmc, sizeof(pmc));
ULONG mem_size = pmc.WorkingSetSize / 1024;
for (DWORD i = 0; i < 10000000; i++) {
int key = rand() % 100000;
key += i;
file_info.parent_fid = key;
data.push_back(make_pair(key, file_info));
}
GetProcessMemoryInfo(handle, &pmc, sizeof(pmc));
cout << "vector插入1000万条数据,耗时:" << (GetTickCount() - nowClock) << "ms" << " 消耗内存:" << pmc.WorkingSetSize / 1024 - mem_size << " K" << endl;
mem_size = pmc.WorkingSetSize / 1024;
nowClock = GetTickCount();
std::sort(data.begin(), data.end());
cout << "vector排序1000万条数据,耗时:" << (GetTickCount() - nowClock) << "ms" << endl;
key = data[rand() % 900000].first;
nowClock = GetTickCount();
if (binary_search(data, key) > -1)
cout << "vector从1000万条数据查找,耗时:" << (GetTickCount() - nowClock) << "ms" << endl;
cout << "===========================================================" << endl;
nowClock = GetTickCount();
unordered_map<DWORDLONG, FileInfo> unordered_map_data;
for (DWORD i = 0; i < 10000000; i++) {
file_info.parent_fid = key;
unordered_map_data[i] = file_info;
}
GetProcessMemoryInfo(handle, &pmc, sizeof(pmc));
cout << "unordered_map插入1000万条数据,耗时:" << (GetTickCount() - nowClock) << "ms" << " 消耗内存:" << pmc.WorkingSetSize / 1024 - mem_size << " K" << endl;
mem_size = pmc.WorkingSetSize / 1024;
nowClock = GetTickCount();
if (unordered_map_data.find(key) != unordered_map_data.end())
cout << "unordered_map从1000万条数据查找,耗时:" << (GetTickCount() - nowClock) << "ms" << endl;
cout << "===========================================================" << endl;
nowClock = GetTickCount();
map<DWORDLONG, FileInfo> map_data;
for (DWORD i = 0; i < 10000000; i++) {
file_info.parent_fid = key;
map_data[i] = file_info;
}
GetProcessMemoryInfo(handle, &pmc, sizeof(pmc));
cout << "map插入1000万条数据,耗时:" << (GetTickCount() - nowClock) << "ms" << " 消耗内存:" << pmc.WorkingSetSize / 1024 - mem_size << " K" << endl;;
mem_size = pmc.WorkingSetSize / 1024;
nowClock = GetTickCount();
if (map_data.find(key) != map_data.end())
cout << "map从1000万条数据查找,耗时:" << (GetTickCount() - nowClock) << "ms" << endl;
网友评论