[Astuce] Mesurer le temps qui passe...
On cherche quelques fois à connaà®tre le temps de "travail" d'une fonction alors voici ma solution :
MPClockStarted()
// Fonction à mesurer
MPClockStoppedForObject(self,@fonctionMesuree);
MPClockStarted()
// Fonction à mesurer
MPClockStoppedForObject(self,@fonctionMesuree);
<br />#pragma mark --- Clock Time ---<br />//-------------------------------------------------------------------------------------------------------------------------------------------------------<br />double _MPClockTimeStopped(BOOL isStopped)<br />{<br /> static double theDouble[10];<br /> static int theIndex=0;<br /><br /> struct timeval theTime;<br /> gettimeofday(&theTime,NULL);<br /> double result=-1;<br /><br /> if (isStopped)<br /> {<br /> theIndex--;<br /> double final=(double)theTime.tv_sec + ((double)theTime.tv_usec / 1000000.0);<br /> double result_d=((double)(final - theDouble[theIndex]) * 1e3);<br /> result=(double)result_d;<br /> if (theIndex<0)<br /> theIndex=0;<br /> }<br /> else<br /> {<br /> theDouble[theIndex]=(double)theTime.tv_sec + ((double)theTime.tv_usec / 1000000.0);<br /> theIndex++;<br /> if (theIndex>9)<br /> {<br /> theIndex=9;<br /> NSLog(@"Error: MPClockTimeStopped - theIndex>10");<br /> return -1;<br /> }<br /> }<br /><br /> return result;<br />}<br /><br />void MPClockStarted()<br />{<br /> _MPClockTimeStopped(NO);<br />}<br /><br />void MPClockStoppedForObject(id aObject, NSString *comment)<br />{<br /> double clockTime=_MPClockTimeStopped(YES);<br /> if (clockTime<1000)<br /> NSLog([NSString stringWithFormat:@"%@ (%@) time: %f ms",aObject,comment,clockTime]);<br /> else<br /> NSLog([NSString stringWithFormat:@"%@ (%@) time: %f sec",aObject,comment,(clockTime/1000.0)]);<br />}<br />//-------------------------------------------------------------------------------------------------------------------------------------------------------<br />
Connectez-vous ou Inscrivez-vous pour répondre.
Réponses
Je fais confiance à "Shark" pour toutes ces choses :P