#include <list>
#include<iostream>
#include<vector>
#include<stdexcept>
#include<string>
#include<cstdlib>//abort()
#include<cstdio>//snprintf();整数转字符
#include<ctime>
#include<algorithm>
#include<array>
#include<string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define NUM 1000000
int main()
{
unordered_multimap<long, string> c;
char buf[10];
clock_t timeStart = clock();
long target = 99999;
for (long i = 0; i < NUM; ++i)
{
snprintf(buf, 10, "%d", rand());
c.insert(pair<long,string>(i,buf));
}
cout << "毫秒: " << (double((clock() - timeStart))/CLOCKS_PER_SEC * 1000 ) << endl;
cout << "undered_multiset.size() = " << c.size() << endl;
cout << "undered_multiset.max_size()= " << c.max_size() << endl;
cout << "undered_multiset.bucket_count()= " << c.bucket_count() << endl;
cout << "undered_multiset.load_factor()= " << c.load_factor() << endl;
cout << "undered_multiset.max_load_factor()= " << c.max_load_factor() << endl;
cout << "undered_multiset.max_bucket_count()= " << c.max_bucket_count() << endl;
for (unsigned i = 0; i < 20; ++i)
{
cout << "bucket #" << i << " has " << c.bucket_size(i) << " elements." << endl;
}
timeStart = clock();
auto pItem = c.find(target);
cout << "c.find() 毫秒: " << (double((clock() - timeStart))/CLOCKS_PER_SEC * 1000 ) << endl;
if (pItem != c.end())
{
cout << "find value: " << pItem->second << endl;
}
else
{
cout << "not find " << endl;
}
return 0;
}
标签:multimap,snprintf,0008,long,include,buf,unordered
From: https://www.cnblogs.com/gom-linwei/p/17320478.html