Andrew Binstock Editor, Unix Review "Bruce tiếp tục ngạc nhiên với cái nhìn sâu sắc của mình vào C + +, và tư duy trong C + + là bộ sưu tập của mình tốt nhất của(lưu ý, tuy nhiên, nếu "" không phải là đã có trong các wordmap một mục mới sẽ được tạo ra). | ticks clock copy ostream_iterator string tmp2 n ticks clock - ticks cout Iterating deqeue ticks endl Knowing now what you do about the inefficiency of adding things to vector because of storage reallocation you may expect dramatic differences between the two. However on a Megabyte text file one compiler s program produced the following measured in platform compiler specific clock ticks not seconds Read into vector 8350 Read into deque 7690 Indexing vector 2360 Indexing deqeue 2480 Iterating vector 2470 Iterating deqeue 2410 A different compiler and platform roughly agreed with this. It s not so dramatic is it This points out some important issues 1. We programmers are typically very bad at guessing where inefficiencies occur in our programs. 2. Efficiency comes from a combination of effects - here reading the lines in and converting them to strings may dominate over the cost of the vector vs. deque. 3. The string class is probably fairly well-designed in terms of efficiency. Of course this doesn t mean you shouldn t use a deque rather than a vector when you know that an uncertain number of objects will be pushed onto the end of the container. On the contrary you should - when you re tuning for performance. But you should also be aware that performance issues are usually not where you think they are and the only way to know for sure where your bottlenecks are is by testing. Later in this chapter there will be a more pure comparison of performance between vector deque and list. Converting between sequences Sometimes you need the behavior or efficiency of one kind of container for one part of your program and a different container s behavior or efficiency in another part of the program. For example you may need the efficiency of a deque when adding objects to the container but the efficiency of a vector when indexing them. Each of the basic sequence containers vector deque and list has a two-iterator constructor indicating the beginning