#include <iostream> using namespace std; float mLastTrackingProgressUpdate = 0.0f; int countOfCalls = 0; void fun(int completedTrackingTime, int totalTrackingTime) { float totalPercent = static_cast<float>(completedTrackingTime) / totalTrackingTime; bool doPostMessageOfProgressUpdate = false; if (mLastTrackingProgressUpdate + 0.01f <= totalPercent || completedTrackingTime == totalTrackingTime) { doPostMessageOfProgressUpdate = true; mLastTrackingProgressUpdate = totalPercent; } if (doPostMessageOfProgressUpdate) { cout<<"update progress for %= "<<totalPercent<<" called for frameN = "<<completedTrackingTime<<endl; countOfCalls += 1; } } int main() { int tot=199941; int i=0; while(i<=tot) { fun(i, tot); i++; } cout<<"Count of calls = "<<countOfCalls; return 0; }
Standard input is empty
update progress for %= 0.010003 called for frameN = 2000 update progress for %= 0.0200059 called for frameN = 4000 update progress for %= 0.0300089 called for frameN = 6000 update progress for %= 0.0400118 called for frameN = 8000 update progress for %= 0.0500148 called for frameN = 10000 update progress for %= 0.0600177 called for frameN = 12000 update progress for %= 0.0700207 called for frameN = 14000 update progress for %= 0.0800236 called for frameN = 16000 update progress for %= 0.0900266 called for frameN = 18000 update progress for %= 0.10003 called for frameN = 20000 update progress for %= 0.110032 called for frameN = 22000 update progress for %= 0.120035 called for frameN = 24000 update progress for %= 0.130038 called for frameN = 26000 update progress for %= 0.140041 called for frameN = 28000 update progress for %= 0.150044 called for frameN = 30000 update progress for %= 0.160047 called for frameN = 32000 update progress for %= 0.17005 called for frameN = 34000 update progress for %= 0.180053 called for frameN = 36000 update progress for %= 0.190056 called for frameN = 38000 update progress for %= 0.200059 called for frameN = 40000 update progress for %= 0.210062 called for frameN = 42000 update progress for %= 0.220065 called for frameN = 44000 update progress for %= 0.230068 called for frameN = 46000 update progress for %= 0.240071 called for frameN = 48000 update progress for %= 0.250074 called for frameN = 50000 update progress for %= 0.260077 called for frameN = 52000 update progress for %= 0.27008 called for frameN = 54000 update progress for %= 0.280083 called for frameN = 56000 update progress for %= 0.290086 called for frameN = 58000 update progress for %= 0.300089 called for frameN = 60000 update progress for %= 0.310091 called for frameN = 62000 update progress for %= 0.320094 called for frameN = 64000 update progress for %= 0.330097 called for frameN = 66000 update progress for %= 0.3401 called for frameN = 68000 update progress for %= 0.350103 called for frameN = 70000 update progress for %= 0.360106 called for frameN = 72000 update progress for %= 0.370109 called for frameN = 74000 update progress for %= 0.380112 called for frameN = 76000 update progress for %= 0.390115 called for frameN = 78000 update progress for %= 0.400118 called for frameN = 80000 update progress for %= 0.410121 called for frameN = 82000 update progress for %= 0.420124 called for frameN = 84000 update progress for %= 0.430127 called for frameN = 86000 update progress for %= 0.44013 called for frameN = 88000 update progress for %= 0.450133 called for frameN = 90000 update progress for %= 0.460136 called for frameN = 92000 update progress for %= 0.470139 called for frameN = 94000 update progress for %= 0.480142 called for frameN = 96000 update progress for %= 0.490145 called for frameN = 98000 update progress for %= 0.500148 called for frameN = 100000 update progress for %= 0.51015 called for frameN = 102000 update progress for %= 0.520153 called for frameN = 104000 update progress for %= 0.530156 called for frameN = 106000 update progress for %= 0.540159 called for frameN = 108000 update progress for %= 0.550162 called for frameN = 110000 update progress for %= 0.560165 called for frameN = 112000 update progress for %= 0.570168 called for frameN = 114000 update progress for %= 0.580171 called for frameN = 116000 update progress for %= 0.590174 called for frameN = 118000 update progress for %= 0.600177 called for frameN = 120000 update progress for %= 0.61018 called for frameN = 122000 update progress for %= 0.620183 called for frameN = 124000 update progress for %= 0.630186 called for frameN = 126000 update progress for %= 0.640189 called for frameN = 128000 update progress for %= 0.650192 called for frameN = 130000 update progress for %= 0.660195 called for frameN = 132000 update progress for %= 0.670198 called for frameN = 134000 update progress for %= 0.680201 called for frameN = 136000 update progress for %= 0.690204 called for frameN = 138000 update progress for %= 0.700207 called for frameN = 140000 update progress for %= 0.710209 called for frameN = 142000 update progress for %= 0.720212 called for frameN = 144000 update progress for %= 0.730215 called for frameN = 146000 update progress for %= 0.740218 called for frameN = 148000 update progress for %= 0.750221 called for frameN = 150000 update progress for %= 0.760224 called for frameN = 152000 update progress for %= 0.770227 called for frameN = 154000 update progress for %= 0.78023 called for frameN = 156000 update progress for %= 0.790233 called for frameN = 158000 update progress for %= 0.800236 called for frameN = 160000 update progress for %= 0.810239 called for frameN = 162000 update progress for %= 0.820242 called for frameN = 164000 update progress for %= 0.830245 called for frameN = 166000 update progress for %= 0.840248 called for frameN = 168000 update progress for %= 0.850251 called for frameN = 170000 update progress for %= 0.860254 called for frameN = 172000 update progress for %= 0.870257 called for frameN = 174000 update progress for %= 0.88026 called for frameN = 176000 update progress for %= 0.890263 called for frameN = 178000 update progress for %= 0.900266 called for frameN = 180000 update progress for %= 0.910269 called for frameN = 182000 update progress for %= 0.920271 called for frameN = 184000 update progress for %= 0.930274 called for frameN = 186000 update progress for %= 0.940277 called for frameN = 188000 update progress for %= 0.95028 called for frameN = 190000 update progress for %= 0.960283 called for frameN = 192000 update progress for %= 0.970286 called for frameN = 194000 update progress for %= 0.980289 called for frameN = 196000 update progress for %= 0.990292 called for frameN = 198000 update progress for %= 1 called for frameN = 199941 Count of calls = 100