//std::vector<int> vec;
TinySTL::vector<int> vec;
ProfilerInstance::start();
int i = 0;
for (; i != 10000; ++i){
vec.push_back(i);
}
ProfilerInstance::finish();
ProfilerInstance::dumpDuringTime();
container
quantity
time(ms)
TinySTL::vector<int>
10万
2
TinySTL::vector<int>
100万
11
TinySTL::vector<int>
1000万
129
std::vector<int>
10万
6
std::vector<int>
100万
16
std::vector<int>
1000万
210
####(2):vector<string>
//std::vector<std::string> vec;
TinySTL::vector<std::string> vec;
ProfilerInstance::start();
int i = 0;
for (; i != 100000; ++i){
vec.push_back(std::string("zouxiaohang"));
}
ProfilerInstance::finish();
ProfilerInstance::dumpDuringTime();
container
quantity
time(ms)
TinySTL::vector<string>
10万
18
TinySTL::vector<string>
100万
181
TinySTL::vector<string>
1000万
2372
std::vector<string>
10万
29
std::vector<string>
100万
232
std::vector<string>
1000万
1972
####(3):circular_buffer<int, N>
TinySTL::circular_buffer<int, 10000> cb(10000, 0);
//boost::circular_buffer<int> cb(10000, 0);
ProfilerInstance::start();
for (int i = 0; i != 10000000; ++i){
cb.push_back(i);
}
ProfilerInstance::finish();
ProfilerInstance::dumpDuringTime();
container
quantity
time(ms)
TinySTL::circular_buffer
1000万
75
TinySTL::circular_buffer
10000万
604
TinySTL::circular_buffer
100000万
5936
boost::circular_buffer
1000万
22
boost::circular_buffer
10000万
252
boost::circular_buffer
100000万
2241
####(4):题目:利用bitmap找出str中未出现的字母
std::string str("abcdefghijklmnpqrstuvwxyz");
TinySTL::bitmap<26> bm;
for (auto it = str.cbegin(); it != str.cend(); ++it){
bm.set(*it - 'a');
}
cout << bm << endl;
cout << bm.size() << endl;
for (int i = 0; i != 26; ++i){
if (!bm.test(i))
cout << "字母" << (char)('a' + i) << "没出现!!!" << endl;
}
输出结果:
111111111111110111111111111000000
32
字母o没出现!!!
####(5):string
//std::string str;
TinySTL::string str;
ProfilerInstance::start();
int i = 0;
for (; i != 1000000; ++i){
str.push_back('x');
}
ProfilerInstance::finish();
ProfilerInstance::dumpDuringTime();
container
quantity
time(ms)
TinySTL::string
100万
7
TinySTL::string
1000万
39
TinySTL::string
10000万
484
std::string
100万
37
std::string
1000万
229
std::string
10000万
1965
####(6):priority_queue<int>
//std::priority_queue<int> pq;
TinySTL::priority_queue<int> pq;
ProfilerInstance::start();
int i = 0;
for (; i != 100000; ++i){
pq.push(i);
}
ProfilerInstance::finish();
ProfilerInstance::dumpDuringTime();
container
quantity
time(ms)
TinySTL::priority_queue<int>
10万
13
TinySTL::priority_queue<int>
100万
97
TinySTL::priority_queue<int>
1000万
1032
std::priority_queue<int>
10万
12
std::priority_queue<int>
100万
67
std::priority_queue<int>
1000万
752
TinySTL::vector<int> v;
int i = 0;
for (; i != 100000; ++i){
v.push_back(i);
}
//std::priority_queue<int> pq(v.begin(), v.end());
TinySTL::priority_queue<int> pq(v.begin(), v.end());
ProfilerInstance::start();
for (i = 0; i != 100000; ++i){
pq.pop();
}
ProfilerInstance::finish();
ProfilerInstance::dumpDuringTime();
//std::deque<int> dq;
TinySTL::deque<int> dq;
ProfilerInstance::start();
const int max = 10000000;
int i = 0;
for (; i != max / 2; ++i){
dq.push_front(i);
}
for (; i != max; ++i){
dq.push_back(i);
}
ProfilerInstance::finish();
ProfilerInstance::dumpDuringTime();
TinySTL::Unordered_set<int> ust(10);
//std::unordered_set<int> ust(10);
const size_t insert_count = 1000000;
const uint64_t query_count = 100000000;
//calculate total insert time
ProfilerInstance::start();
for (size_t i = 0; i != insert_count; ++i){
ust.insert(i);//per insert time
}
ProfilerInstance::finish();
ProfilerInstance::dumpDuringTime();
//calculate total query time
ProfilerInstance::start();
for (uint64_t i = 0; i != query_count; ++i){
ust.count(i);//per query time
}
ProfilerInstance::finish();
ProfilerInstance::dumpDuringTime();
container
quantity
insert time(ms)
query time(ms)
TinySTL::unordered_set<int>
1万/1亿
8
97
TinySTL::unordered_set<int>
10万/10亿
139
1000
TinySTL::unordered_set<int>
100万/100亿
1214
9546
std::unordered_set<int>
1万/1亿
64
101
std::unordered_set<int>
10万/10亿
884
953
std::unordered_set<int>
100万/100亿
2781
9682
####(14):sort
std::random_device rd;
const int len = 10000000;
int arr[len];
std::generate(std::begin(arr), std::end(arr), [&rd](){return rd(); });
ProfilerInstance::start();
TinySTL::sort(std::begin(arr), std::end(arr));
//std::sort(std::begin(arr), std::end(arr));
ProfilerInstance::finish();
ProfilerInstance::dumpDuringTime();
请发表评论