I call a computationally expensive function inside a loop:
for( int j = 0; j < Max; ++j ) {
// ...
processQueuedEvents(); // Computationally expensive call
// ...
}
However, I don't need to run the expensive function on every single loop iteration, so I want to call it periodically:
for( int j = 0; j < Max; ++j ) {
// ...
if ( /* The condition I'm talking about */ )
processQueuedEvents(); // Computationally expensive call
// ...
}
At this point, I need to develop a proper condition for my periodic call. The condition should correlate to Max
, I mean, if Max
is larger, the expensive call is less-frequent and if Max
is smaller the expensive call is more-frequent.
Does anybody have any suggestions or hints? For some reason, I have a hard time coming up with a proper condition.