欢迎来到天天文库
浏览记录
ID:30840003
大小:61.00 KB
页数:13页
时间:2019-01-04
《程序运行时间的计算》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、程序运行时间的计算ThemethodforcalculatingtherunningtimeoftheprogramIhavetwocollectionstocontributetooneThisisafunctionthatiscommonlyusedinWindowstocomputetherunningtimeoftheprogram;DWORDdwStart=GetTickCount();//runyourprogramcodehereDWORDdwEnd二GetTickCount();Dwend-dwstartisyourprogramruntime,inmillisecondsTh
2、isfunctionisonlyaccurateto55ms,onetickis55ms・#inelude#ineludeUsingnamespaceSTD.Intmain(intargc,char*argv[])DWORDstartandend;Start二GetTickCount();For(int1二0;I<1000;I++)"Youareagoodchild!,z<3、yGetTickCount(),buttheaccuracyishigherDWORDdwStart二timeGetTime();//runyourprogramcodehereDWORDdwEnd二timeGetTime();Dwend-dwstartisyourprogramruntime,inmillisecondsAlthoughthereturnedvalueunitshouldbems,thelegendisonly10ms・#inelude#include#pragmacomment(lib,^winmm・Lib")Usingnamesp4、aceSTD.Intmain(intargc,char*argv[]){DWORDstartandend;Start二timeGetTime()For(int1二0;I<100;I++)"Youareagoodchild!,?<5、standardcfunction.Clock_tclock(void);#includeClock_t二clock();LongSEC二t/CLOCKS_PER_SEC;He'srecordingtheclockcycle,andtheimplementationdoesn,tlookveryprecise,itneedstobetested;4#includeInclude//UsingnamespaceSTD;Intmain(){Time_tbegin,end;Doubleduration;Thebegin二clock()6、;//here,syourcodeEnd二clock();Duration=double(end一begin)/CLOCKS_PER_SEC;Thecout<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<}5UnixtimeisrelevantandisstandardlibraryThesearein〈time・H〉Thetimegmfunctionsimplyturnsthestructtmstructureintoatime_tstructureanddoesnotusetimezoneinformation.Astructtm(tm);MktimeUS7、EStimezoneinformationAstructtm(tm);ThetimelocalfunctionistheGNUextensionwiththeposixfunctionmktime(struct)(structtm*tm);Thegmtimefunctionsimplyturnsthetime_tstructureintoastructtmstructureanddoesnotus
3、yGetTickCount(),buttheaccuracyishigherDWORDdwStart二timeGetTime();//runyourprogramcodehereDWORDdwEnd二timeGetTime();Dwend-dwstartisyourprogramruntime,inmillisecondsAlthoughthereturnedvalueunitshouldbems,thelegendisonly10ms・#inelude#include#pragmacomment(lib,^winmm・Lib")Usingnamesp
4、aceSTD.Intmain(intargc,char*argv[]){DWORDstartandend;Start二timeGetTime()For(int1二0;I<100;I++)"Youareagoodchild!,?<5、standardcfunction.Clock_tclock(void);#includeClock_t二clock();LongSEC二t/CLOCKS_PER_SEC;He'srecordingtheclockcycle,andtheimplementationdoesn,tlookveryprecise,itneedstobetested;4#includeInclude//UsingnamespaceSTD;Intmain(){Time_tbegin,end;Doubleduration;Thebegin二clock()6、;//here,syourcodeEnd二clock();Duration=double(end一begin)/CLOCKS_PER_SEC;Thecout<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<}5UnixtimeisrelevantandisstandardlibraryThesearein〈time・H〉Thetimegmfunctionsimplyturnsthestructtmstructureintoatime_tstructureanddoesnotusetimezoneinformation.Astructtm(tm);MktimeUS7、EStimezoneinformationAstructtm(tm);ThetimelocalfunctionistheGNUextensionwiththeposixfunctionmktime(struct)(structtm*tm);Thegmtimefunctionsimplyturnsthetime_tstructureintoastructtmstructureanddoesnotus
5、standardcfunction.Clock_tclock(void);#includeClock_t二clock();LongSEC二t/CLOCKS_PER_SEC;He'srecordingtheclockcycle,andtheimplementationdoesn,tlookveryprecise,itneedstobetested;4#includeInclude//UsingnamespaceSTD;Intmain(){Time_tbegin,end;Doubleduration;Thebegin二clock()
6、;//here,syourcodeEnd二clock();Duration=double(end一begin)/CLOCKS_PER_SEC;Thecout<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<}5UnixtimeisrelevantandisstandardlibraryThesearein〈time・H〉Thetimegmfunctionsimplyturnsthestructtmstructureintoatime_tstructureanddoesnotusetimezoneinformation.Astructtm(tm);MktimeUS
7、EStimezoneinformationAstructtm(tm);ThetimelocalfunctionistheGNUextensionwiththeposixfunctionmktime(struct)(structtm*tm);Thegmtimefunctionsimplyturnsthetime_tstructureintoastructtmstructureanddoesnotus
此文档下载收益归作者所有