-
Notifications
You must be signed in to change notification settings - Fork 4
/
05_test_deque.cpp
61 lines (53 loc) · 1.44 KB
/
05_test_deque.cpp
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
#include <deque>
#include <string>
#include <ctime>
#include <stdexcept>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include "assist.h"
using namespace std;
void test_deque(long& value)
{
cout << "test_deque()......" << endl;
deque<string> c;
char buf[10];
clock_t timeStart = clock();
for(long i=0; i<value; ++i)
{
try{
snprintf(buf, 10, "%d", rand() % 10000);
c.push_back(string(buf));
}
catch(exception& p){
cout << "i=" << i << p.what() << endl;
abort();
}
}
cout << "milli-seconds:" << clock() - timeStart << endl;
cout << "deque.size()=" << c.size() << endl;
cout << "deque.max_size()=" << c.max_size() << endl;
cout << "deque.front()=" << c.front() << endl;
cout << "deque.back()=" << c.back() << endl;
string target = get_a_target_string();
timeStart = clock();
deque<string>::iterator pItem = ::find(c.begin(), c.end(), target); // 调用std的find()
cout << "::find(), milli-seconds:" << clock() - timeStart << endl;
if(pItem != c.end())
{
cout << "found, " << *pItem << endl;
}
else
{
cout << "not found" << endl;
}
timeStart = clock();
::sort(c.begin(), c.end()); // 调用std中的sort()
cout << "c.sort(), milli-seconds:" << clock() - timeStart << endl;
}
int main()
{
long value = 1000000;
test_deque(value);
return 0;
}