-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
129 lines (95 loc) · 2.51 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include<iostream>
#include<string>
#include<vector>
#include<sys/time.h>
#include "Vector.h"
// using namespace std;
using namespace selfstl;
int main(){
struct timeval tv1;
gettimeofday(&tv1, NULL);
int start_sec1 = tv1.tv_sec;
int start_usec1 = tv1.tv_usec;
const int max1 = 10000;
Vector<bool> v1;
for (int i = 0; i < max1; i++)
{
v1.insert(v1.begin(), true);
}
gettimeofday(&tv1, NULL);
int end_sec1 = tv1.tv_sec;
int end_usec1 = tv1.tv_usec;
double time_diff1 = (end_sec1 - start_sec1) * 1000000 + (end_usec1 - start_usec1);
std::cout << time_diff1 / 1000 / max1 << "ms" << std::endl;
struct timeval tv2;
gettimeofday(&tv2, NULL);
int start_sec2 = tv2.tv_sec;
int start_usec2 = tv2.tv_usec;
const int max2 = 10000;
std::vector<bool> v2;
for (int i = 0; i < max2; i++)
{
v2.insert(v2.begin(), true);
}
gettimeofday(&tv2, NULL);
int end_sec2 = tv2.tv_sec;
int end_usec2 = tv2.tv_usec;
double time_diff2 = (end_sec2 - start_sec2) * 1000000 + (end_usec2 - start_usec2);
std::cout << time_diff2 / 1000 / max2 << "ms" << std::endl;
// //creat
// Vector<int> v;
// //push_back
// v.push_back(1);
// v.push_back(2);
// v.push_back(3);
// v.show();
// //end
// Vector<int>::Iterator it = v.end();
// std::cout<<"v.end():"<<*it<<std::endl;
// //begin
// Vector<int>::Iterator it = v.begin();
// std::cout<<"v.begin():"<<*it<<std::endl;
// //=
// Vector<int> v2;
// v2 = v;
// v2.show();
// //data
// int *p = v.data();
// *p = 10;
// v.show();
// //swap
// Vector<int> v2;
// v2.push_back(4);
// v2.push_back(5);
// v2.show();
// v2.swap(v);
// v2.show();
// //front
// std::cout<<"v.front() :"<<v.front()<<std::endl;
// //back
// std::cout<<"v.back() :"<<v.back()<<std::endl;
// //pop_back
// v.pop_back();
// v.show();
// //size
// std::cout<<"m_size :"<<v.size()<<std::endl;
// //capacity
// std::cout<<"m_capacity :"<<v.capacity()<<std::endl;
// //reverse
// v.reserve(16);
// v.show();
// //resize
// v.resize(32);
// v.show();
// //at
// std::cout<<"v[2] :"<<v.at(2)<<std::endl;
// //[]
// std::cout<<"v[2] :"<<v[2]<<std::endl;
// //empty
// std::cout<<"v is empty :"<<v.empty()<<std::endl;
// //clear
// v.clear();
// v.show();
std::cout<<"main cout test"<<std::endl;
return 0;
}