-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_unordered_multiset.hpp
executable file
·82 lines (70 loc) · 2.14 KB
/
test_unordered_multiset.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef _TEST_UNORDERED_MULTISET_H
#define _TEST_UNORDERED_MULTISET_H
#include <unordered_set>
#include <stdexcept>
#include <string>
#include <iostream>
#include <ctime>
#include <cstdio> // snprintf()
#include <cstdlib> // abort()
#include <algorithm>
#include "pub.h"
using std::unordered_multiset;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::exception;
using std::find;
using std::sort;
namespace jj08
{
void test_unordered_multiset(long& totalCount)
{
cout << "\ntest_unordered_multiset()......... \n";
unordered_multiset<string> c;
char buf[10];
clock_t timeStart = clock();
for (long i = 0; i < totalCount; ++i)
{
try {
snprintf(buf, 10, "%d", rand() % 65535);
c.insert(string(buf));
}
catch (std::exception& e) {
cout << "i=" << i << e.what() << endl;
abort();
}
}
cout << "milli-seconds:" << (clock() - timeStart) << endl;
cout << "unordered_multiset.size()= " << c.size() << endl;
cout << "unordered_multiset.max_size()= " << c.max_size() << endl;
cout << "unordered_multiset.bucket_count()= " << c.bucket_count() << endl;
cout << "unordered_multiset.load_factor()= " << c.load_factor() << endl;
cout << "unordered_multiset.max_load_factor()= " << c.max_load_factor() << endl;
cout << "unordered_multiset.max_bucket_count()= " << c.max_bucket_count() << endl;
for (unsigned long i = 0; i < 20; ++i) {
cout << "bucket #" << i << " has " << c.bucket_size(i) << " elements.\n";
}
string target = get_a_target_string();
{
timeStart = clock();
auto pItem = ::find(c.begin(), c.end(), target); // ±Èc.find(...)ÂýºÜ¶à
cout << "::find(), mill-seconds: " << (clock() - timeStart) << endl;
if (pItem != c.end())
cout << "found, " << *pItem << endl;
else
cout << "not found! " << endl;
}
{
timeStart = clock();
auto pItem = c.find(target); // ±È::find(...)¿ìºÜ¶à
cout << "c.find(), mill-seconds: " << (clock() - timeStart) << endl;
if (pItem != c.end())
cout << "found, " << *pItem << endl;
else
cout << "not found! " << endl;
}
}
}
#endif