Sergiy Svirkov
Sergiy Svirkov

Reputation: 1

C++. How to speed up the execution of a method or cycle?

I had one problem. It is necessary to speed up the operation of one method. In this method there are three or four cycles of this type:

for (vector<(ANY_TYPE) *>::const_iterator iter = VECTOR_NAME.begin(); iter != VECTOR_NAME.end(); ++iter)

The duration of one such cycle can vary from 0 to 1 second. But in this method, I have such cycles called several thousand times, of which there are more than a hundred cases when such a cycle lasts one second. In total, due to this, the execution of my main method takes between 155 and 190 seconds.

I would like to speed up the execution of this method. Is there an identical cycle in C++ that would almost always take zero seconds or ? Is there another way for me to speed up the execution of the method? I am using C++ standard 11.

Can anyone recommend anything? Thanks in advance.

I've tried replacing similar cycles with cycles like:

for (ANY_TYPE * &iter: VECTOR_NAME)

But nothing helps. And I think the use of such a cycle is illogical.

Upvotes: 0

Views: 76

Answers (0)

Related Questions