-
Notifications
You must be signed in to change notification settings - Fork 0
/
testVector.cpp
53 lines (46 loc) · 1.31 KB
/
testVector.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
#include <vector>
#include <iostream>
#include <string>
#include <stdexcept>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <forward_list>
namespace llf{
void test_vector(const long& value) {
std::cout << "\ntest_vector().......\n";
std::vector<std::string> c;
char buf[10];
clock_t timeStart = clock();
for(long i=0;i<value;i++)
{
try{
snprintf(buf, 10, "%d", rand());
c.push_back(std::string(buf));
}
catch(std::exception& e){
std::cout << "i= " << i << e.what() << std::endl;
abort();
}
}
std::cout << sizeof(int) << std::endl;
std::cout << "million seconds " << clock() - timeStart << std::endl;
std::cout << "vector.size() = " << c.size() << std::endl;
std::cout << "vector.front() = " << c.front() << std::endl;
std::cout << "vector.back() = " << c.back() << std::endl;
std::cout << "vector.data() = " << c.data() << std::endl;
std::cout << "vector.capacity() = " << c.capacity() << std::endl;
auto target = std::find(c.begin(), c.end(), c.front());
if (target != c.end()){
std::cout << *target << std::endl;
}
else
{
std::cout << "not found" << std::endl;
}
}
}
int main(){
llf::test_vector(1'000'000);
return 0;
}