boost::unordered_map 和 std::map 的效率,内存比较

在Windows环境下,boost::unordered_map的查找和插入速度比std::map快五倍,内存消耗相对较少。在Release模式下,unordered_map消耗1.2GB,而std::map消耗1.5GB。如果不需要排序,推荐使用unordered_map。
摘要由CSDN通过智能技术生成
// 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 " <&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值