Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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


Ïà¹ØÎĵµ£º

LinuxÏ»ñµÃϵͳʱ¼äµÄCÓïÑÔµÄʵÏÖ·½·¨

 LinuxÏ»ñµÃϵͳʱ¼äµÄCÓïÑÔµÄʵÏÖ·½·¨
#include<time.h>  //CÓïÑÔµÄÍ·Îļþ
#include<stdio.h>  //CÓïÑÔµÄI/O
void main()
{
time_t now;    //ʵÀý»¯time_t½á¹¹
struct tm  *timenow;    //ʵÀý»¯tm½á¹¹Ö¸Õë
time(&now);
//timeº¯Êý¶ÁÈ¡ÏÖÔÚµ ......

Windows via C/C++£ºÏ̵߳÷¶È——¸ÅÊö

»ùÓÚÓÅÏȼ¶µÄ²Ù×÷ϵͳ£¨preemptive operating system£©±ØÐëʹÓÃijÖÖËã·¨ÒÔ¾ö¶¨CPUÈçºÎµ÷¶ÈϵͳÖеÄỊ̈߳¬±¾Õ½«ÌÖÂÛWindows VistaʹÓõĵ÷¶ÈËã·¨¡£ ÎÒÃÇ֮ǰÌÖÂÛ¹ýÏ̵߳ÄÉÏÏÂÎĽṹCONTEXT£¬ÆäÖк¬ÓÐÏß³Ì×îºóÒ»´ÎÖ´ÐÐʱCPU¼Ä´æÆ÷×éµÄ״̬¡£ ²Ù×÷ϵͳÿ20ºÁÃë¼ì²éϵͳÖÐËùÓÐÏß³ÌÄں˶ÔÏóµÄ״̬£¬ÆäÖÐһЩ¶ÔÏó±»ÈÏΪÊǿɵ÷¶È£ ......

c/c++ÃæÊÔÌâ

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

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

 ÄÚ´æ·ÖÅ䷽ʽÓÐÈýÖÖ£º
£¨1£© ´Ó¾²Ì¬´æ´¢ÇøÓò·ÖÅä¡£ÄÚ´æÔÚ³ÌÐò±àÒëµÄʱºò¾ÍÒѾ­·ÖÅäºÃ£¬Õâ¿éÄÚ´æÔÚ³ÌÐòµÄ
Õû¸öÔËÐÐÆڼ䶼´æÔÚ¡£ÀýÈçÈ«¾Ö±äÁ¿£¬static ±äÁ¿¡£
£¨2£© ÔÚÕ»ÉÏ´´½¨¡£ÔÚÖ´Ðк¯Êýʱ£¬º¯ÊýÄÚ¾Ö²¿±äÁ¿µÄ´æ´¢µ¥Ôª¶¼¿ÉÒÔÔÚÕ»ÉÏ´´½¨£¬º¯
ÊýÖ´ÐнáÊøʱÕâЩ´æ´¢µ¥Ôª×Ô¶¯±»ÊÍ·Å¡£Õ»ÄÚ´æ·ÖÅäÔËËãÄÚÖÃÓÚ´¦ÀíÆ÷µ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ