Click here to Skip to main content
15,911,035 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: VC++ 7.0? Pin
Nish Nishant3-Jan-02 16:30
sitebuilderNish Nishant3-Jan-02 16:30 
GeneralRe: VC++ 7.0? - nick query Pin
Nish Nishant3-Jan-02 16:32
sitebuilderNish Nishant3-Jan-02 16:32 
GeneralRe: VC++ 7.0? - nick query Pin
Michael P Butler4-Jan-02 1:14
Michael P Butler4-Jan-02 1:14 
GeneralSTL optimization Pin
Not Active3-Jan-02 15:03
mentorNot Active3-Jan-02 15:03 
GeneralRe: STL optimization Pin
Christian Graus3-Jan-02 15:10
protectorChristian Graus3-Jan-02 15:10 
GeneralRe: STL optimization Pin
Not Active4-Jan-02 1:18
mentorNot Active4-Jan-02 1:18 
GeneralRe: STL optimization Pin
Thomas Freudenberg4-Jan-02 1:45
Thomas Freudenberg4-Jan-02 1:45 
GeneralRe: STL optimization Pin
Tim Smith4-Jan-02 2:24
Tim Smith4-Jan-02 2:24 
There is no way in hell a container class could ever be as optimized as an unbounded, well defined array fill.

Here are some of the differences between your FooArray and FooList.

1. As someone else pointed out, you are using a list and not a vector. A vector would be a more valid test.

2. std::vector does bounds checking and reallocates the data buffer using a doubling algorithm. Your FooArray routine does no bounds checking and is limited to only 50 elements.

3. Passing the list (or vector) is just a bit slower. You can double the performance by passing in a destination list into the routine via a reference.

4. Only runing the routine once is not a valid test. In my tests in release mode, executing each routine 10000 times yielded this information:

list - 6770 ms
vector - 841 ms
array - 30 ms

With the optimization of passing the list and vector into the routine:

list - 3175 ms
vector - 811 ms
array - 30 ms

If you don't destruct the list or vector each loop iteration and just invoke .clear on them, the numbers are as follows:

list - 3090 ms
vector - 290 ms
array - 30 ms

The final optimization I can think of is pre allocating the vector to size 50. However, that change made no difference. The reason being that the clear routine just sets the size back to zero and doesn't deallocate the vector data. Thus, since after the first pass the vector is already sized to 50, invoking reserve to preallocate the vector to 50 does nothing. Which shows the cost of all the memory allocation in vector. 800+ ms to 300 by removing all the allocations. Thus, vector has 270 ms of bookkeeping overhead that FooArray doesn't have.

5. Most optimizers can not handle deeply nested inlining well. It is very easy to optimize the hell out of FooArray. However, the compiler has much more trouble optimizing FooList since the implementation is deeply nested and more complex.


Tim Smith
Descartes Systems Sciences, Inc.
GeneralRe: STL optimization Pin
CodeGuy4-Jan-02 2:38
CodeGuy4-Jan-02 2:38 
GeneralRe: STL optimization Pin
Tim Smith4-Jan-02 7:20
Tim Smith4-Jan-02 7:20 
GeneralRe: STL optimization Pin
Not Active4-Jan-02 9:46
mentorNot Active4-Jan-02 9:46 
GeneralRe: STL optimization Pin
Tim Smith4-Jan-02 10:13
Tim Smith4-Jan-02 10:13 
GeneralRe: STL optimization Pin
CodeGuy4-Jan-02 2:32
CodeGuy4-Jan-02 2:32 
GeneralRe: STL optimization Pin
Tim Smith4-Jan-02 7:25
Tim Smith4-Jan-02 7:25 
GeneralRe: STL optimization Pin
CodeGuy4-Jan-02 8:12
CodeGuy4-Jan-02 8:12 
GeneralRe: STL optimization Pin
Tim Smith4-Jan-02 8:53
Tim Smith4-Jan-02 8:53 
GeneralRe: STL optimization Pin
CodeGuy4-Jan-02 9:02
CodeGuy4-Jan-02 9:02 
GeneralRe: STL optimization Pin
Not Active4-Jan-02 9:47
mentorNot Active4-Jan-02 9:47 
GeneralPicture and Win 95 Pin
Matt Newman3-Jan-02 13:43
Matt Newman3-Jan-02 13:43 
GeneralRe: Picture and Win 95 Pin
Philip Patrick3-Jan-02 13:47
professionalPhilip Patrick3-Jan-02 13:47 
GeneralRe: Picture and Win 95 Pin
Matt Newman3-Jan-02 14:27
Matt Newman3-Jan-02 14:27 
GeneralAPI guide Pin
KinHei3-Jan-02 12:27
KinHei3-Jan-02 12:27 
GeneralRe: API guide Pin
Nish Nishant3-Jan-02 16:36
sitebuilderNish Nishant3-Jan-02 16:36 
GeneralRe: API guide Pin
Michael P Butler4-Jan-02 1:18
Michael P Butler4-Jan-02 1:18 
GeneralEdit Controls Pin
John L. DeVito3-Jan-02 11:10
professionalJohn L. DeVito3-Jan-02 11:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.