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


Ïà¹ØÎĵµ£º

javaµ÷ÓÃC/C++дµÄdll

JavaÓïÑÔ±¾Éí¾ßÓпçƽ̨ÐÔ£¬Èç¹ûͨ¹ýJavaµ÷ÓÃDLLµÄ¼¼Êõ·½±ãÒ×Óã¬Ê¹ÓÃJava¿ª·¢Ç°Ì¨½çÃæ¿ÉÒÔ¸ü¿ìËÙ£¬Ò²ÄÜ´øÀ´¿çƽ̨ÐÔ¡£
Javaµ÷ÓÃC/C++дºÃµÄDLL¿âʱ£¬ÓÉÓÚ»ù±¾Êý¾ÝÀàÐͲ»Í¬¡¢Ê¹ÓÃ×Ö½ÚÐòÁпÉÄÜÓвîÒ죬ËùÒÔÔÚ²ÎÊý´«µÝ¹ý³ÌÖÐÈÝÒ׳öÏÖÎÊÌ⣬DLLÖпÉÄÜÐèÒª×öÏàÓ¦µÄת»»¡£
ʹÓÃJavaµ÷ÓÃDLL¶¯Ì¬Á´½Ó¿âµÄ·½°¸Í¨³£ÓÐÈýÖÖ£ºJNI, Ja ......

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

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

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 ......

c/c++ÃæÊÔÌâ

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

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

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