BOOL GetProcessTimes(
  HANDLE hProcess,           // specifies the process of interest
  LPFILETIME lpCreationTime, // when the process was created
  LPFILETIME lpExitTime,     // when the process exited
  LPFILETIME lpKernelTime,   // time the process has spent in kernel
                             // mode
  LPFILETIME lpUserTime      // time the process has spent in user mode
);
 
BOOL GetThreadTimes(
  HANDLE hThread,             // specifies the thread of interest
  LPFILETIME lpCreationTime,  // when the thread was created
  LPFILETIME lpExitTime,      // when the thread was destroyed
  LPFILETIME lpKernelTime,    // time the thread has spent in kernel
                              // mode
  LPFILETIME lpUserTime       // time the thread has spent in user mode
);
 
  Windows NT: Requires version 3.5 or later.
  Windows: Unsupported.
  Windows CE: Unsupported.
  Header: Declared in winbase.h.
  Import Library: Use kernel32.lib.

解决方案 »

  1.   

    The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601.Is it Enough?
      

  2.   

    好像问题的内容和标题是两回事儿?我就回答一个吧
    Win32 API提供两个与系统计数有关的函数,QueryPerformanceFrequency()用来取得计数的频率。另一个是QueryPerformanceCounter(),它可以返回计数器的计数值,要计算程序的耗时,只需要取得开始和结束时的计数差除以计数频率就得到时间。可是你需要知道不同芯片的计数频率。
    (对于PII和PPro,计数频率和时钟频率相同。Pentium133的计数频率是1.193MHz....)
      

  3.   

    是的GetTickCount返回毫秒级...一般开始前用GetTickCount得到起始时间
    在操作执行完毕后再用GetTickCount得到结束时间.
    两者相减就是所用的时间,,,
    DWORD dwStartTime = ::GetTickCount();
    // 操作
    ...
    DWORD dwCount = ::GetTickCount() - dwStartTime;
    int nMMSenconds = dwCount / 1000;
    int nSenconds = dwCount / 1000;
    int nMinutes = nSenconds / 60;
    int nHours = nMinutes / 60;
    nMMSenconds = nMMSenconds % 1000;
    nSenconds = nSenconds % 60;
    nMinutes = nMinutes % 60;
    TRACE("干这个活儿共花费:\t%d小时%d分钟%d秒%d毫秒\n", nHours, nMinutes, nSenconds, nMMSenconds);
    你如果嫌它不精确,那那........
      

  4.   

    ns级的定时精度好像不太可能,对Windows这种非实时操作系统来说。
      

  5.   

    panda_w(好想睡啊!)贤弟所说的1.193...MHz是IBM/PC的标准脉冲间隔,它作为8086的指令周期。后来机器越来越快了,但给计时器的基准时钟仍是这个,是为了向后兼容,所有IBM PC的后代都是这样。但不同机器QueryPerformanceFrequency的结果可能会不一样。
    100ns不可能,除非自已作定时器的驱动程序,或者象panda_w(好想睡啊!)提的方法,不断地查现在的counter数,直到到了100ns,不过你的程序可干不了别的了,单独作个线程也可以。