#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>
using namespace std;
#define NUM 1000000
int main()
{
multiset<string> c;
char buf[10];
clock_t timeStart = clock();
string target = "1999";
for (long i = 0; i < NUM; ++i)
{
snprintf(buf, 10,"%d", rand());
c.insert(string(buf));
target = buf;
}
cout << "毫秒: " << (double((clock() - timeStart))/CLOCKS_PER_SEC * 1000 ) << endl;
cout << "multiset.size() = " << c.size() << endl;
cout << "multiset.max_size() = " << c.max_size() << endl;
timeStart = clock();
auto pItem = ::find(c.begin(),c.end(),target);
cout << "::find查找结束,毫秒: " << (double((clock() - timeStart))/CLOCKS_PER_SEC * 1000 ) << endl;
if (pItem != c.end())
{
cout << "found: " << *pItem << endl;
}
else
{
cout << "not found! " << endl;
}
timeStart = clock();
pItem = c.find(target);//比::find()快很多才对
cout << "mem find 查找结束 毫秒: " << (double((clock() - timeStart))/CLOCKS_PER_SEC * 1000 ) << endl;
if (pItem != c.end())
{
cout << "fonud, " << *pItem << endl;
}
else
{
cout << "not fonud, " << endl;
}
}