The vector class really likes and provides a certain amount of convenience due to performance, which is great when you do not really need performance.
If you really need performance, it wonโt be too painful to go around the vector class and go directly to the simple old handmade array, whether statically or dynamically distributed. Then 1) the time during which you are currently indexing should disappear significantly, speeding up your application by this amount, and 2) you can proceed to the fact that the โnext big thingโ takes time in your application.
EDIT: Most programs have much more speedup options than you might expect. To illustrate this, I did a cross-cutting project . If I can sum it up very quickly, it will look like this:
The original time is 2.7 ms per โjobโ (the number of โjobsโ can vary to get enough lead time to analyze it).
The first section showed that approximately 60% of the time was spent in vector operations, including indexing, adding, and deleting. I replaced a similar vector class from MFC, and the time was reduced to 1.8 ms / task. (This is an acceleration of 1.5 or 50%.)
Even with this array class, approximately 40% of the time was spent in [] indexing the operator. I wanted it to be indexed directly, so I made it index directly, and not through the operator function. This reduced the time to 1.5 ms / task, acceleration by 1.2 times.
Now about 60% of the time adds / removes elements in arrays. An additional share was spent on โnewโ and โdeleteโ. I decided to pull out the arrays and do two things. One of them was to use self-linked lists and to combine used objects. First shortened time to 1.3 ms (1.15x). The second reduced it to 0.44 ms (2.95x).
At that time, I found that about 60% of the time was in the code that I wrote to index the list (as if it were an array). I decided that this could be done simply by pointing directly to the list. Result: 0.14 ms (3.14x).
Now I find that almost all the time is spent on the diagnostic I / O line that I printed on the console. I decided to get rid of this: 0.0037 ms (38x).
I could keep going, but I stopped. The total time per task was reduced using a mixed coefficient of about 700x.
What I want you to take away is that you need the performance to be bad enough to deviate from what can be considered an accepted way of doing things, you donโt need to stop after one bottleneck. Just because you got a lot of acceleration does not mean that they are no more. In fact, the next bottleneck may be larger than the first, in terms of acceleration coefficient. So raise your expectations for the acceleration you can get and go for the scrapping.
source share