// Test_Boost_Unordered.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "boost/unordered_map.hpp"
#include <iostream>
#include <map>
#include "time.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
{
time_t first_time = time(0);
boost::unordered_map<int, int> test_hash;
for (int i = 0; i < 50000000; i++)
{
test_hash.insert(std::pair<int, int>(i, i));
}
cout << test_hash.size() << endl;
time_t second_time = time(0);
for (int i = 0; i< 50000001; ++i)
{
boost::unordered_map<int, int>::iterator iter = test_hash.find(i);
if (iter == test_hash.end())
{
cout << "false" << endl;
}
}
time_t third_time = time(0);
cout << "second - first " << second_time - first_time << endl;
cout << "third - second " <&
boost::unordered_map 和 std::map 的效率,内存比较
在Windows环境下,boost::unordered_map的查找和插入速度比std::map快五倍,内存消耗相对较少。在Release模式下,unordered_map消耗1.2GB,而std::map消耗1.5GB。如果不需要排序,推荐使用unordered_map。
摘要由CSDN通过智能技术生成