Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Windows via C/C++£ºÏ̵߳ÄÖ´ÐÐʱ¼ä

¼ÆËãÏß³ÌÖ´ÐÐijÏîÈÎÎñÏûºÄµÄʱ¼äʱ£¬Ðí¶à¿ª·¢ÈËÔ±»áµ÷ÓÃGetTickCount/GetTickCount64±àдÈçϵĴúÂ룺
// Get the current time (start time)
ULONGLONG qwStartTime = GetTickCount64();
// Perform complex algorithm here
// Subtract start time from current time to get duration
ULONGLONG dwElapsedTime = GetTickCount64() - qwStartTime;
Õâ¶Î´úÂë¼ÙÉ赱ǰÏ̲߳»»á±»Öжϡ£È»¶øÔÚWindowsÕâÑùµÄ»ùÓÚÓÅÏȼ¶µÄ²Ù×÷ϵͳÖУ¬¿ª·¢ÈËÔ±ÎÞ·¨µÃÖªÏ̱߳»µ÷¶ÈµÄ׼ȷʱ¼ä¡£µ±Ïß³ÌÔÚÖ´ÐÐÈÎÎñÖб»ÖжÏʱ£¬Ê¹ÓÃÉÏÃæµÄ·½·¨¸ù±¾ÎÞ·¨»ñµÃÏß³ÌËùÏûºÄµÄʱ¼ä¡£ÎÒÃÇÐèÒªÒ»¸ö¿ÉÒÔ·µ»ØÏß³ÌÏûºÄµÄCPUʱ¼ä£¨¼È±»µ÷¶Èʱ¼ä£©µÄº¯Êý£¬ÐÒÔ˵ÄÊÇ£¬ÔÚVista֮ǰµÄ²Ù×÷ϵͳÒѾ­ÌṩÁËGetThreadTimes×öµ½ÕâÒ»µã£º
BOOL GetThreadTimes(HANDLE hThread,
PFILETIME pftCreationTime,
PFILETIME pftExitTime,
PFILETIME pftKernelTime,
PFILETIME pftUserTime);
GetThreadTimeº¯Êý»á½«Ïß³ÌÏà¹ØµÄʱ¼äÐÅϢдÈëΪÆä´«µÝµÄPFILETIME²ÎÊýÖУ¬¸÷¸ö²ÎÊý·µ»ØÖµµÄº¬ÒåÈçϱíËùʾ£º
²ÎÊý
ÒâÒå
pftCreationTime
´Ó1601Äê1ÔÂ1ºÅÁ賿¿ªÊ¼µ½Ö¸¶¨Ï̱߳»´´½¨Ê±µÄʱ¼ä£¬ÒÔ100ÄÉÃëΪµ¥Î»
pftExitTime
´Ó1601Äê1ÔÂ1ºÅÁ賿¿ªÊ¼µ½Ö¸¶¨Ï߳̽áÊøËù»¨µÄʱ¼ä£¬ÒÔ100ÄÉÃëΪµ¥Î»£¬¼ÙÈçÏß³ÌÉÐδÖÕÖ¹£¬Ôò¸Ãֵ䶨Òå
pftKernelTime
Ïß³ÌÔÚÄÚºËģʽÏÂÔËÐÐËù»¨µÄʱ¼ä£¬ÒÔ100ÄÉÃëΪµ¥Î»
pftUserTime
Ïß³ÌÔÚÓû§Ä£Ê½ÏÂÔËÐÐËù»¨µÄʱ¼ä£¬ÒÔ100ÄÉÃëΪµ¥Î»
ʹÓÃGetThreadTimes¿ÉÒÔ¼ÆËãÏß³ÌËùÏû·ÑµÄCPUʱ¼ä£¬±ÈÈçÏÂÃæµÄ´úÂ룺
__int64 FileTimeToQuadWord(PFILETIME pft) {
return (Int64ShllMod32(ptf->dwHighDateTime, 32) | ptf->dwLowDateTime);
}
void PerformLongOperation() {
FILETIME ftKernelTimeStart, ftKernelTimeEnd;
FILETIME ftUserTiimeStart, ftUserTimeEnd;
FILETIME ftDummy;
__int64 qwKernelTimeElapsed, qwUserTimeElapsed, qwTotalTimeElapsed;
// Get starting times
GetThreadTimes(GetCurrentThread(), &ftDummy, &ftDummy, &ftKernelTimeStart, &ftUserTimeStart);
// Perform complex algorithm here
...
// Get the ending times
GetThreadTimes(GetCurrentThread(), &ftDummy, &ftDummy, &ftKernelTimeEnd, &ftUserTimeEnd);
// Get the elapsed kernel and user times by c


Ïà¹ØÎĵµ£º

C/C++¾­µäÅÅÐòËã·¨

ÅÅÐòËã·¨ÊÇÒ»ÖÖ»ù±¾²¢ÇÒ³£ÓõÄËã·¨¡£ÓÉÓÚʵ¼Ê¹¤×÷Öд¦ÀíµÄÊýÁ¿¾Þ´ó£¬ËùÒÔÅÅÐòËã·¨¶ÔËã·¨±¾ÉíµÄËÙ¶ÈÒªÇóºÜ¸ß¡£
    ¶øÒ»°ãÎÒÃÇËùνµÄËã·¨µÄÐÔÄÜÖ÷ÒªÊÇÖ¸Ëã·¨µÄ¸´ÔÓ¶È£¬Ò»°ãÓÃO·½·¨À´±íʾ¡£ÔÚºóÃæÎÒ½«¸ø³öÏêϸµÄ˵Ã÷¡£
    ¶ÔÓÚÅÅÐòµÄËã·¨ÎÒÏëÏÈ×öÒ»µã¼òµ¥µÄ½éÉÜ£¬Ò²ÊǸøÕâÆªÎÄÕÂÀíÒ»¸öÌá¸Ù ......

c/c++ÃæÊÔÌâ

½ñÌìÈ¥ÃæÊÔÒ»¼Ò¹«Ë¾£¬ÌîÁËÒ»·Ý“»§¿Úµ÷²é”£¬È»ºó¾ÍÊÇ×öÒ»·ÝÃæÊÔÌ⣬ÌâÄ¿ºÜ¼òµ¥
1¡¢¸Ä´íÌ⣬¸øÒ»¶Î³ÌÐò£¬Ö¸³ö´íÎó
2¡¢Socket×èÈûºÍ·Ç×èÈû±à³Ì£¬·Ç×èÈûµÄʵÏÖÔ­Àí
3¡¢TCP/IPÓëOSIÆß²ãÄ£ÐÍ
TCP/IP²Î¿¼Ä£Ð͹²ÓÐÎå²ã£ºÓ¦Óò㡢´«Êä²ã¡¢»¥ÁªÍø²ãºÍÖ÷»úÖÁÍøÂç²ã¡£
ÓëOSI²Î¿¼Ä£ÐÍÏà±È£¬TCP/IP²Î¿¼Ä£ÐÍûÓбíʾ²ãºÍ» ......

dz̸CÄÚ´æ·ÖÅä1

¹ØÓÚCÓïÑÔÄÚ´æ·½ÃæµÄ»°ÌâÒªÕæËµÆðÀ´µÄ»°Äǿ֞ÍûͷÁË£¬ËùÒÔ±¾ÎĽö½öÊÇÒ»¸ödz̸¡£
¹ØÓÚÄÚ´æÎÊÌâ
²»Í¬Æ½Ì¨Ö®¼äÓÐÒ»¶¨µÄÇø±ð¡£±¾ÎÄËùÖ¸µÄƽ̨ÊÇx86µÄLinux
ƽ̨
ÓÃCÓïÑÔ×ö³ÌÐò£¨ÆäʵÆäËûÓïÑÔÒ²Ò»Ñù£©£¬²»½öÒªÊìϤÓï·¨£¬ÆäʵºÜ¶àÏà¹ØµÄ±³¾°ÖªÊ¶Ò²ºÜÖØÒª¡£ÔÚѧϰºÍÑо¿CÓïÑÔÖÐÄÚ´æ·ÖÅäµÄÎÊÌâǰ£¬Ê×ÏÈÒªÁ˽âÒ»ÏÂLinux·ÖÅ䏸 ......

[ÃæÊÔÌâ]C»ù´¡ÌâÄ¿

±àÕß°´:·Ç³£»ù±¾¹ØÓÚCÓïÑÔµÄÎÊÌâ,Ò»¸öÐÅÏ¢Àà(¼ÆËã»ú,×ÊѶ¹¤³Ì,µç×Ó¹¤³Ì, ͨÐÅ
¹¤³Ì)רҵµÄ±¾¿Æ±ÏÒµÉúÓ¦¸Ã´ïµ½µÄˮƽ¡£ÌâÄ¿²»ÄÑ,È«²¿¶¼ÄÜ¿ìËٵشðÍ꣬µ±È»Ò²ÐèÒª
Ò»¶¨µÄ֪ʶ´¢±¸¡£
¶ÔÓÚ´ó¶àÊýÈË£¬ÎÒÃÇÔ¤ÆÚÄã¿ÉÄÜ´ð´í 1)  4)  15)Ì⣬ËùÒÔ´ð´í3µÀÒÔÄڵģ¬ÎÒÃÇÈÏΪ
ÄãºÜ°ô
´ð´í5µÀÌâÒÔ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ