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
Ïà¹ØÎĵµ£º
Delphi Óë C/C++ Êý¾ÝÀàÐͶÔÕÕ±í
DelphiÊý¾ÝÀàÐÍC/C++
ShorInt
8λÓзûºÅÕûÊý
char
Byte
8λÎÞ·ûºÅÕûÊý
BYTE,unsigned short
SmallInt
16λÓзûºÅÕûÊý
short
Word
16λÎÞ·ûºÅÕûÊý
unsigned short
Integer,LongInt
32λÓзûºÅÕûÊý
int,long
Cardinal,LongWord/DWORD
32λÎÞ·ûºÅÕûÊý
unsigned long
Int6 ......
CÊÇÒ»¸ö½á¹¹»¯ÓïÑÔ£¬ÈçÌ·ÀÏÒ¯×ÓËù˵£ºËüµÄÖصãÔÚÓÚËã·¨ºÍÊý¾Ý½á¹¹¡£C³ÌÐòµÄÉè¼ÆÊ×Òª¿¼ÂǵÄÊÇÈçºÎͨ¹ýÒ»¸ö¹ý³Ì£¬¶ÔÊäÈ루»ò»·¾³Ìõ¼þ£©½øÐÐÔËËã´¦ÀíµÃµ½Êä³ö£¨»òʵÏÖ¹ý³Ì£¨ÊÂÎñ£©¿ØÖÆ£©£¬¶ø¶ÔÓÚC++£¬Ê×Òª¿¼ÂǵÄÊÇÈçºÎ¹¹ÔìÒ»¸ö¶ÔÏóÄ£ÐÍ£¬ÈÃÕâ¸öÄ£ÐÍÄܹ»ÆõºÏÓëÖ®¶ÔÓ¦µÄÎÊÌâÓò£¬ÕâÑù¾Í¿ÉÒÔͨ¹ý»ñÈ¡¶ÔÏóµÄ״̬ÐÅÏ¢µÃµ½Êä³ö»òʵÏÖ¹ ......
º¯Êý - ÉùÃ÷¡¢¶¨Òå¡¢µ÷ÓÃ
¡¡¡¡1. Èç¹ûº¯ÊýûÓÐÉùÃ÷, Ó¦¸ÃÔÚµ÷ÓÃÇ°¶¨Òå:
#include¡¡<stdio.h>
/*¡¡¶¨ÒåÇó´óÖµº¯Êý¡¡*/
int¡¡MAX(int¡¡x,¡¡int¡¡y)¡¡{
¡¡¡¡if¡¡(x¡¡>¡¡y)
¡¡¡¡¡¡¡¡return¡¡x;
¡¡¡¡else
¡¡¡¡¡¡¡¡return¡¡y;
}¡¡
/*¡¡¶¨ÒåÇóСֵº¯Êý¡¡*/
int¡¡MIN(int¡¡x,¡¡int¡¡y)¡¡{
¡¡¡¡return¡¡x¡¡&l ......
½ñÌìÈ¥ÃæÊÔÒ»¼Ò¹«Ë¾£¬ÌîÁËÒ»·Ý“»§¿Úµ÷²é”£¬È»ºó¾ÍÊÇ×öÒ»·ÝÃæÊÔÌ⣬ÌâÄ¿ºÜ¼òµ¥
1¡¢¸Ä´íÌ⣬¸øÒ»¶Î³ÌÐò£¬Ö¸³ö´íÎó
2¡¢Socket×èÈûºÍ·Ç×èÈû±à³Ì£¬·Ç×èÈûµÄʵÏÖÔÀí
3¡¢TCP/IPÓëOSIÆß²ãÄ£ÐÍ
TCP/IP²Î¿¼Ä£Ð͹²ÓÐÎå²ã£ºÓ¦Óò㡢´«Êä²ã¡¢»¥ÁªÍø²ãºÍÖ÷»úÖÁÍøÂç²ã¡£
ÓëOSI²Î¿¼Ä£ÐÍÏà±È£¬TCP/IP²Î¿¼Ä£ÐÍûÓбíʾ²ãºÍ» ......