#if U_PLATFORM_USES_ONLY_WIN32_API # define VC_EXTRALEAN # define WIN32_LEAN_AND_MEAN # include <windows.h> #else # if U_PLATFORM == U_PF_OS390 && !defined(__UU) # define __UU /* Universal Unix - for struct timeval */ # endif # include <time.h> # include <sys/time.h> # include <unistd.h> #endif
/** *ThisAPIprovidesfunctionsforperformingperformancemeasurement *Thereare3mainusagescenarios. *i)Loopuntilathresholdtimeisreached: *Example: *<code> *typedefParamsParams; *structParams{ *char16_t*target; *int32_ttargetLen; *constchar16_t*source; *int32_tsourceLen; *UNormalizationModemode; *} *voidNormFn(void*param){ *Params*parameters=(Params*)param; *UErrorCodeerror=U_ZERO_ERROR; *unorm_normalize(parameters->source,parameters->sourceLen,parameters->mode,0,parameters->target,parameters->targetLen,&error); *if(U_FAILURE(error)){ *printf("Normalizationfailed\n"); *} *} * *intmain(){ *// time the normalization function *doubletimeTaken=0; *Paramsparam; *param.source// set up the source buffer *param.target// set up the target buffer *....soon... *UTimertimer; *// time the loop for 10 seconds at least and find out the loop count and time taken *timeTaken=utimer_loopUntilDone((double)10,(void*)param,NormFn,&loopCount); *} *</code> * *ii)Measurethetimetaken *Example: *<code> *doubleperfNormalization(NormFnfn,constchar*mode,Line*fileLines,int32_tloopCount){ *intline; *intloops; *UErrorCodeerror=U_ZERO_ERROR; *char16_t*dest=nullptr; *int32_tdestCapacity=0; *intlen=-1; *doubleelapsedTime=0; *intretVal=0; * *char16_tarr[5000]; *dest=arr; *destCapacity=5000; *UTimerstart; * *// Initialize cache and ensure the data is loaded. *// This loop checks for errors in Normalization. Once we pass the initialization *// without errors we can safelly assume that there are no errors while timing the *// function *for(loops=0;loops<10;loops++){ *for(line=0;line<gNumFileLines;line++){ *if(opt_uselen){ *len=fileLines[line].len; *} * *retVal=fn(fileLines[line].name,len,dest,destCapacity,&error); *#ifU_PLATFORM_HAS_WIN32_API *if(retVal==0){ *fprintf(stderr,"NormalizationofstringinWindowsAPIfailedformode%s.ErrorNo:%iatlinenumber%i\n",mode,GetLastError(),line); *return0; *} *#endif *if(U_FAILURE(error)){ *fprintf(stderr,"NormalizationofstringinICUAPIfailedformode%s.Error:%satlinenumber%i\n",mode,u_errorName(error),line); *return0; *} * *} *} * *//compute the time * *utimer_getTime(&start); *for(loops=0;loops<loopCount;loops++){ *for(line=0;line<gNumFileLines;line++){ *if(opt_uselen){ *len=fileLines[line].len; *} * *retVal=fn(fileLines[line].name,len,dest,destCapacity,&error); * *} *} * *returnutimer_getElapsedSeconds(&start); *} *</code> * *iii)Letahigherlevelfunctiondothecalculationofconfidencelevelsetc. *Example: *<code> *voidperf(UTimer*timer,char16_t*source,int32_tsourceLen,char16_t*target,int32_ttargetLen,int32_tloopCount,UNormalizationModemode,UErrorCode*error){ *int32_tloops; *for(loops=0;loops<loopCount;loops++){ *unorm_normalize(source,sourceLen,target,targetLen,mode,error); *} *utimer_getTime(timer); *} *voidmain(constchar*argsc,intargv){ *// read the file and setup the data *// set up options *UTimerstart,timer1,timer2,timer3,timer4; *doubleNFDTimeTaken,NFCTimeTaken,FCDTimeTaken; *switch(opt){ *case0: *utimer_getTime(start); *perf(timer1,source,sourceLen,target,targetLen,loopCount,UNORM_NFD,&error); *NFDTimeTaken=utimer_getDeltaSeconds(start,timer1); *case1: *timer_getTime(start); *perf(timer2,source,sourceLen,target,targetLen,loopCount,UNORM_NFC,&error); *NFCTimeTaken=utimer_getDeltaSeconds(start,timer2); *perf(timer3,source,sourceLen,target,targetLen,loopCount,UNORM_FCD,&error); *// ........so on ............. *} *// calculate confidence levels etc and print * *} * *</code> *
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.